import { Dispatch, SetStateAction } from 'react';

export type MeProps = {
  isGroupAdmin: boolean;
  isGroupOwner: boolean;
};
export type ChatMessagesProps = {
  sender: string;
  message: string;
  recipient: string; // conversation_id
  message_id: number;
  attachment_urls: string[] | null;
  sender_id: string;
  conversation_id: string;
  sent_at: Date;
};
export type ContactsProps = {
  read: boolean;
  username: string;
  user_id: string;
  id: number;
  type: 'direct' | 'group';
  conversation_id: string;
  last_active: string;
  last_message: string;
  last_message_time: string;
  last_message_sender: string;
};

export type ParticipantsProps = {
  user_id: string;
  username: string;
  isadmin: boolean;
  isowner: boolean;
};

export type FileWithPreviewProps = {
  file: File;
  preview: string | null;
};

export type UserType = {
  username: string | null;
  id: string | null;
};

export type ChatContextType = {
  contactsList: ContactsProps[];
  currentContact: ContactsProps | null;
  cursor: number;
  messages: ChatMessagesProps[];
  errorMessage: string | null;
  hasMoreMessages: boolean;
  me: MeProps;
  groupOwner: string | undefined;

  setContactsList: Dispatch<SetStateAction<ContactsProps[]>>;
  setCurrentContact: Dispatch<SetStateAction<ContactsProps | null>>;
  setCursor: Dispatch<SetStateAction<number>>;
  setMessages: Dispatch<SetStateAction<ChatMessagesProps[]>>;
  setErrorMessage: Dispatch<SetStateAction<string | null>>;
  setHasMoreMessages: Dispatch<SetStateAction<boolean>>;
  setMe: Dispatch<SetStateAction<MeProps>>;
  setGroupOwner: Dispatch<SetStateAction<string | undefined>>;

  initializeContact: (newContact: ContactsProps) => Promise<boolean>;
  fetchMessages: (conversation_id: string) => Promise<void>;
  messageHandler: (msg: ChatMessagesProps) => void;
  updateContactStatus: (contactObj: ContactsProps, read: boolean) => void;
  fetchPreviousMessages: (contact: string | null) => Promise<void>;
};
