import {ChatEventBase, ChatEventSubtype, ChatEventType} from './eventBase';
import {HuDataMember} from './user';

/**
 * Current user reaction. Used to toggle a reaction
 */
export interface UserReaction {
  channel: string;
  clientMsgId: string;
  reactionName: string;
  userId: number;
  /**
   * Used to apply insert or delete in the DB. Should not be used in the UI.
   */
  action?: 'add' | 'remove';
}

/**
 * Reaction info is used in the store layer and in the UI
 */
export interface ReactionInfo {
  summary: {
    name: string;
    count: number;
    text: string;
    hasUserReaction: boolean;
  }[];
  /**
   * Reactions that the current user has added to the message
   */
  userReactions: string[];
  /**
   * List of reactions with users info
   */
  list: ReactionWithUser[];
}

export interface ReactionWithUser extends Omit<Reaction, 'users'> {
  users: HuDataMember[];
}

export interface Reaction {
  name: string;
  count: number;
  users: string[];
}

export interface ReactionEvent
  extends ChatEventBase<
    ChatEventType.messageReaction,
    ChatEventSubtype.add | ChatEventSubtype.remove
  > {
  channel: string;
  user: string;
  ts: string;
  username: string;
  client_msg_id: string;
  reactions: Reaction[];
  hu_data: {
    message_ts: string;
    version: number;
    position: number;
  };
}
