import type { ChatMessage, Poll, Role, Stream, Token } from "./types";

export type NewStream = {
    name: string;
};

export type NewToken = {
    streamId: string;
    role: Role;
    tokenHash: string;
};

export type NewChatMessage = {
    streamId: string;
    platform: string;
    author: string;
    message: string;
};

export type NewPoll = {
    streamId: string;
    question: string;
    isOpen: boolean;
    votesYes: number;
    votesNo: number;
};

export type PollPatch = Partial<Pick<Poll, "question" | "isOpen" | "votesYes" | "votesNo">>;
export type SetupState = {
    setupCompletedAt: string | null;
    usedSetupKeyHashes: string[];
    setupLocked: boolean;
};

export interface DataStore {
    init(): Promise<void>;
    createStream(input: NewStream): Promise<Stream>;
    listStreams(): Promise<Stream[]>;
    getStreamById(streamId: string): Promise<Stream | null>;
    createToken(input: NewToken): Promise<Token>;
    getTokenByHash(tokenHash: string): Promise<Token | null>;
    listTokensByStream(streamId: string): Promise<Token[]>;
    revokeTokenById(tokenId: string): Promise<boolean>;
    createChatMessage(input: NewChatMessage): Promise<ChatMessage>;
    listChatMessagesByStream(streamId: string): Promise<ChatMessage[]>;
    createPoll(input: NewPoll): Promise<Poll>;
    updatePoll(pollId: string, patch: PollPatch): Promise<Poll | null>;
    listPollsByStream(streamId: string): Promise<Poll[]>;
    getSetupState(): Promise<SetupState>;
    markSetupKeyUsed(setupKeyHash: string): Promise<void>;
    markSetupCompleted(completedAt: string): Promise<void>;
    hasActiveAdminToken(): Promise<boolean>;
}
