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

export type Chat = {
  chatUid: number | null;
  groupChatToken: string | null;
  name: string;
  avatar: string | null;
  short: string;
  sentBy: number;
  updated: Date;
  status: 1 | 2 | 3 | 4;
  unreadCount: number;
  lastMessageId: number;
  pin: 0 | 1;
  pinOrder: number;
  archive: 0 | 1;
  archiveOrder: number;
  attachementName: string;
  encrypted: 0 | 1;
  muted: 0 | 1;
  userType: 'normal' | 'not_exist' | 'blocked';
  announcement: 0 | 1;
  canSendMessages: 0 | 1
};

export type Blocked = {
  userId: number;
  firstName: string;
  lastName: string;
  avatar: string | null;
};

export type ChatProps = {
  uid: number | null;
  groupToken: string | null;
  name: string;
  avatar: string | null;
  pin: 0 | 1;
  archive: 0 | 1;
  muted: 0 | 1;
  userType: 'normal' | 'not_exist' | 'blocked';
  announcement: 0 | 1;
};

export interface Attachement {
  id: number;
  filename: string;
  filetype: string;
  attachment_small_url?: string;
  attachment_full_url?: string;
  lat?: number;
  lng?: number;
  attachment_link?: string;
}

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;
  reactions: string;
  edits: string;
  attachement: -1 | Attachement;
  encrypted: 0 | 1;
  isSending?: boolean;
};

export type MessageGroupSimple = {
  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;
  reactions: string;
  edits: string;
  attachement: -1 | Attachement;
  encrypted: 0 | 1;
  sender_avatar: string | null;
  sender_name: string;
  isSending?: boolean;
};

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

export type GroupMessage = MessageGroupSimple & {
  reply_to: MessageGroupSimple;
  sender_avatar: string | null;
  sender_name: string;
};

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

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

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

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