import { IMessage } from "@/api/resources/ChatMessages";

export interface IResponse<T> {
    status: "success" | string
    data: T
}

export interface ServerToClientEvents {
    chat_joined: (response: IResponse<null>) => void;
    receive_message: (message: IMessage) => void;
    current_balance: (balance: IResponse<ICurrentBalance>) => void;
    session_started: (response: IResponse<ISessionStarted>) => void;
    session_ended: (response: IResponse<boolean>) => void;
    chat_left: (response: IResponse<boolean>) => void;
    balance_updated: (response: IResponse<IBalanceUpdated>) => void;
}

export interface IBalanceUpdated {
    balance: number
}

export interface ICurrentBalance {
    chatId: string;
    cost: number;
    maxFinishedAt: string;
    balance: number;
}

export interface ISessionStarted {
    chatId: string;
    chatSessionId: string;
    cost: number;
    startedAt: string;
    maxFinishedAt: string;
    balance: number;
}

export interface ClientToServerEvents {
    join_chat: (payload: IChatIDPayload) => void;
    send_message: (message: ISendMessagePayload) => void;
    read_message: (messages: IReadMessagePayload) => void;
    start_session: (payload: IChatIDPayload) => void;
    end_session: (payload: IChatIDPayload) => void;
    leave_chat: (payload: IChatIDPayload) => void;
    fetch_balance: (payload: IChatIDPayload) => void;
}

export interface IChatIDPayload {
    chatId: string;
}

export interface ISendMessagePayload {
    chatId: string;
    message: string;
}

export interface IReadMessagePayload {
    messages: string[];
}