import { EventType } from '../types/event.type';
import { InfoResponse } from '../protocols/info';

export interface Info<T = {}> {
  // 이벤트SEQ
  seq: number;
  // 이벤트타입
  type: EventType;
  // 발신자SEQ
  senderSeq: number;
  // 발신일시
  sendDate: string;
  // 발신내용
  sentMessage: string;
  // // 발신내용
  sentMessageJson?: T;
  // 수신자수
  receiverCount: number;
  // 강퇴 요청자명
  exitForcingRequestUserName?: string;
}

export function isCopyable(eventType: EventType): boolean {
  return (
    EventType.Character === eventType ||
    EventType.Translation === eventType ||
    EventType.MassTranslation === eventType
  );
}

export function isRecalled(eventType: EventType): boolean {
  return EventType.RecalledMessage === eventType;
}

export function isRecallable(event: Info<any>, userSeq: number): boolean {
  return (
    event.senderSeq === userSeq && event.type !== EventType.RecalledMessage
  );
}

export function isForwardable(
  event: Info,
  eventInfoStatus: InfoResponse
): boolean {
  if (
    event.type === EventType.Plan ||
    event.type === EventType.AllimTms ||
    event.type === EventType.AllimElephant
  ) {
    return false;
  } else if (event.type === EventType.File) {
    if (
      !!eventInfoStatus &&
      !!eventInfoStatus.validFileBaseSeq &&
      eventInfoStatus.validFileBaseSeq <= event.seq
    ) {
      // valid..
      return true;
    } else {
      // expired..
      return false;
    }
  }
  return true;
}
