import { IMessage } from 'react-native-gifted-chat';

export type Chat = {
  uid: number;
  name: string;
  avatar: string | null;
  short: string;
  sent_by: number;
  updated: Date;
  status: 1 | 2 | 3 | 4;
  unread_count: number;
  last_message_id: number;
  pin: 0 | 1;
  pin_order: number;
  archive: 0 | 1;
  archive_order: number;
  attachement_name: string;
  encrypted: 0 | 1;
  muted: 0 | 1;
};

export type Blocked = {
  id: number;
  first_name: string;
  last_name: string;
  avatar: string | null;
};

export type ChatProps = {
  uid: number;
  name: string;
  avatar: string | null;
  pin: 0 | 1;
  archive: 0 | 1;
  muted: 0 | 1;
};

export type MessageSimple = {
  id: number;
  sender: number;
  recipient: number;
  text: string;
  status: 1 | 2 | 3 | 4;
  sent_datetime: Date;
  received_datetime: Date | null;
  read_datetime: Date | null;
  reply_to_id: number; // -1 if not a reply
  reactions: string; // JSON object '{}'
  edits: string; // JSON object '{}'
  attachement: any; // -1 if no attachment
  encrypted: 0 | 1;
};

export type Message = MessageSimple & {
  reply_to: MessageSimple;
};

export interface CustomMessage extends IMessage {
  _id: number;
  replyMessage?: {
    text: string;
    id: number;
    name: string;
  } | null;
  deleted: boolean;
  attachment: string | null;
  reactions: Reaction[] | {};
}

export type Reaction = {
  datetime: Date;
  reaction: string;
  uid: number;
};

export type Routes = {
  key: 'all' | 'unread' | 'archived' | 'blocked';
  title: string;
  icon?: string;
};

export type WarningProps = {
  title: string;
  buttonTitle?: string;
  message: string;
  action: () => void;
};
