import {Message, MessageStatus} from './message';
import {Block} from './blockMessage';

export enum ExtendedMessageType {
  ListPadding = 'list_padding',
  Default = 'default',
  SystemMessage = 'system_message',
  UnreadPill = 'unread_pill',
  DatePill = 'date_pill',
  UnsupportedMessage = 'unsupported_message',
  DeletedMessage = 'deleted_message',
  Reactions = 'reactions',
}

export type ExtendedMessageAttributes<T extends ExtendedMessageType, D> = {
  id: string;
  ts: string; // message.ts ( for scrollToMessageByTs )
  extendedType: T;
  data: D;
  isFirst?: boolean;
  isChannel: boolean;
  useExtraMarginTop?: boolean;
};

export type DefaultMessage = ExtendedMessageAttributes<
  ExtendedMessageType.Default,
  Message
> & {
  showSenderInfo: boolean;
  isSentByCurrentUser: boolean;
};

export type DatePillMessage = ExtendedMessageAttributes<
  ExtendedMessageType.DatePill,
  {
    date: string;
    version: number;
  }
>;

export type UnreadPillMessage = ExtendedMessageAttributes<
  ExtendedMessageType.UnreadPill,
  {
    unreadCount: number;
    isLastRead: boolean;
    version: number;
  }
>;

export type SystemMessage = ExtendedMessageAttributes<
  ExtendedMessageType.SystemMessage,
  {
    blocks: Block[];
    userId: string;
    username: string;
    version: number;
    height: number;
  }
>;

export type UnsupportedMessage = ExtendedMessageAttributes<
  ExtendedMessageType.UnsupportedMessage,
  Message
> & {
  showSenderInfo: boolean;
  isSentByCurrentUser: boolean;
};

export type DeletedMessage = ExtendedMessageAttributes<
  ExtendedMessageType.DeletedMessage,
  {
    ts: string;
    version: number;
    username: string;
    sender_profile_picture?: string;
    status?: MessageStatus;
    client_msg_id: string;
  }
> & {
  showSenderInfo: boolean;
  isSentByCurrentUser: boolean;
};

export type ListPaddingMessage = ExtendedMessageAttributes<
  ExtendedMessageType.ListPadding,
  {
    version: number;
  }
>;

export type ReactionsMessage = ExtendedMessageAttributes<
  ExtendedMessageType.Reactions,
  {
    clientMsgId: string;
    messageTs?: string;
    channel: string;
    isSentByCurrentUser: boolean;
  }
>;

export type ExtendedMessage =
  | ListPaddingMessage
  | DefaultMessage
  | DatePillMessage
  | UnreadPillMessage
  | SystemMessage
  | UnsupportedMessage
  | DeletedMessage
  | ReactionsMessage;
