import { IChatMessage, IGetChatsListResponse } from "@/entities/chats/types";
import { Currency } from "@/types";

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

export interface IBalanceUpdated {
  balance: number;
}

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

export interface IRefillModalsProduct {
  id: string;
  key: string;
  credits: number;
  price: number;
  currency: Currency;
  bonus?: number | null;
}

export interface IRefillModals {
  oneClick?: {
    timer: number;
    product: IRefillModalsProduct;
    autoTopUp: {
      value: boolean;
      after: number;
      credits: number;
      minutes: number;
    };
  };
  products?: IRefillModalsProduct[];
  hasShownTimerModal?: boolean;
}

export interface IAutoTopUpRequest {
  productId: string;
  key: string;
  isAutoTopUp?: boolean;
}

export interface IUnreadMessagesCount {
  unreadCount: number;
}

export interface ClientToServerEvents {
  join_chat: (data: { chatId: string }) => void;
  leave_chat: (data: { chatId: string }) => void;
  send_message: (data: { chatId: string; message: string }) => void;
  read_message: (data: { messages: string[] }) => void;
  start_session: (data: { chatId: string }) => void;
  end_session: (data: { chatId: string }) => void;
  fetch_balance: (data: { chatId: string }) => void;
  deposit: (data: { amount: number }) => void;
  confirm_timer_modal_shown: () => void;
  request_refill_modal: (data: { chatId: string }) => void;
}

export interface ServerToClientEventsBaseData<T> {
  status: string;
  data: T;
}

export interface ServerToClientEvents {
  chat_joined: (data: ServerToClientEventsBaseData<null>) => void;
  chat_left: (data: ServerToClientEventsBaseData<boolean>) => void;
  receive_message: (data: IChatMessage[]) => void;
  current_balance: (
    data: ServerToClientEventsBaseData<ICurrentBalance>
  ) => void;
  balance_updated: (
    data: ServerToClientEventsBaseData<IBalanceUpdated>
  ) => void;
  session_started: (
    data: ServerToClientEventsBaseData<ISessionStarted>
  ) => void;
  session_ended: (data: ServerToClientEventsBaseData<boolean>) => void;
  show_refill_modals: (
    data: ServerToClientEventsBaseData<IRefillModals>
  ) => void;
  auto_topup_request: (
    data: ServerToClientEventsBaseData<IAutoTopUpRequest>
  ) => void;
  chats_updated: (data: IGetChatsListResponse) => void;
  unread_messages_count: (data: IUnreadMessagesCount) => void;
}
