import { createAction, props } from '@ngrx/store';

import {
  Info,
  InfoRequest as EventInfoRequest,
  InfoResponse as EventInfoResponse,
  SendRequest as SendEventRequest,
  SendResponse as SendEventResponse,
  ReadRequest,
  DelRequest,
  DelResponse,
  CancelRequest,
  CancelResponse,
  SendNotification,
  ReadNotification,
  CancelNotification,
  DelNotification,
  EventJson,
  ReadResponse,
  SendRequest
} from '@ucap/protocol-event';

import {
  InfoRequest as FileInfoRequest,
  InfoResponse as FileInfoResponse,
  FileDownloadInfo,
  FileInfo
} from '@ucap/protocol-file';

/**
 * retrieve list of event
 */
export const events = createAction(
  '[ucap::chat::chatting] events',
  props<{ req: EventInfoRequest }>()
);
/**
 * Success of events request
 */
export const eventsSuccess = createAction(
  '[ucap::chat::chatting] events Success',
  props<{
    eventInfoList: Info<EventJson>[];
    res: EventInfoResponse;
    remainEvent: boolean;
  }>()
);
/**
 * Failure of events request
 */
export const eventsFailure = createAction(
  '[ucap::chat::chatting] events Failure',
  props<{ roomId: string; error: any }>()
);
/**
 * retrieve list of event
 */
export const moreEvents = createAction(
  '[ucap::chat::chatting] events more',
  props<{ roomId: string }>()
);

/**
 * retrieve list of file information
 */
export const fileInfos = createAction(
  '[ucap::chat::chatting] fileInfos',
  props<{ req: FileInfoRequest }>()
);
/**
 * Success of fileInfos request
 */
export const fileInfosSuccess = createAction(
  '[ucap::chat::chatting] fileInfos Success',
  props<{
    fileInfoList: FileInfo[];
    fileInfoCheckList: FileDownloadInfo[];
    res: FileInfoResponse;
  }>()
);
/**
 * Failure of fileInfos request
 */
export const fileInfosFailure = createAction(
  '[ucap::chat::chatting] fileInfos Failure',
  props<{ roomId: string; error: any }>()
);

/**
 * add new event
 */
export const addEvent = createAction(
  '[ucap::chat::chatting] addEvent',
  props<{
    roomId: string;
    info: Info<EventJson>;
    SVC_TYPE?: number;
    SSVC_TYPE?: number;
  }>()
);
/**
 * add new event Success.
 */
export const addEventSuccess = createAction(
  '[ucap::chat::chatting] addEvent Success',
  props<{
    roomId: string;
    info: Info<EventJson>;
  }>()
);

export const read = createAction(
  '[ucap::chat::chatting] read',
  props<ReadRequest>()
);

export const readSuccess = createAction(
  '[ucap::chat::chatting] read Success',
  props<ReadResponse>()
);

// export const readNotification = createAction(
//   '[ucap::chat::chatting] Read Notification',
//   props<ReadNotification>()
// );

export const readFailure = createAction(
  '[ucap::chat::chatting] read Failure',
  props<{ error: any }>()
);

export const send = createAction(
  '[ucap::chat::chatting] Send',
  props<{ senderSeq: string; req: SendEventRequest }>()
);

export const sendSuccess = createAction(
  '[ucap::chat::chatting] Send Success',
  props<{
    senderSeq: string;
    res: SendEventResponse;
  }>()
);

export const sendFailure = createAction(
  '[ucap::chat::chatting] Send Failure',
  props<{ error: any }>()
);

export const sendNotification = createAction(
  '[ucap::chat::chatting] Send Notification',
  props<{ noti: SendNotification }>()
);

/** 대화 삭제 */
export const del = createAction(
  '[ucap::chat::chatting] Delete',
  props<DelRequest>()
);
export const delFailure = createAction(
  '[ucap::chat::chatting] Delete Failure',
  props<{ error: any }>()
);
export const delNotification = createAction(
  '[ucap::chat::chatting] Delete Notification || Response',
  props<{ noti: DelNotification | DelResponse }>()
);
/** 대화 삭제시 열린 대화방의 대화 내용 갱신 */
export const delEventList = createAction(
  '[ucap::chat::chatting] Delete InfoList',
  props<{
    roomId: string;
    eventSeqs: number[];
  }>()
);

/** forward */
export const forward = createAction(
  '[ucap::chat::chatting] Forward',
  props<{
    senderSeq: string;
    req: SendRequest;
    trgtUserSeqs?: string[];
    trgtRoomSeq?: string;
  }>()
);
/** chat forward failure */
export const forwardFailure = createAction(
  '[ucap::chat::chatting] Forward failure',
  props<{ error: any }>()
);

export const forwardAfterRoomOpen = createAction(
  '[ucap::chat::chatting] Forward after room open',
  props<{
    senderSeq: string;
    req: SendRequest;
    trgtUserSeqs?: string[];
    trgtRoomSeq?: string;
  }>()
);

export const roomOpenAfterForward = createAction(
  '[ucap::chat::chatting] Room open after forward',
  props<{
    senderSeq: string;
    req: SendRequest;
    trgtUserSeqs?: string[];
    trgtRoomSeq?: string;
  }>()
);

/** 대화 회수 */
export const cancel = createAction(
  '[ucap::chat::chatting] Cancel',
  props<CancelRequest>()
);
export const cancelFailure = createAction(
  '[ucap::chat::chatting] Cancel Failure',
  props<{ error: any }>()
);
export const cancelNotification = createAction(
  '[ucap::chat::chatting] Cancel Notification || Response',
  props<{ noti: CancelNotification | CancelResponse }>()
);
/** 대화 회수시 열린 대화방의 대화 내용 갱신 */
export const updateEventList = createAction(
  '[ucap::chat::chatting] Update InfoList',
  props<{
    roomId: string;
    eventSeq: number;
    sentMessage: string;
  }>()
);