import { createAction, props } from '@ngrx/store';
import {
  InfoRequest,
  Info,
  InfoResponse,
  SendResponse,
  SendRequest,
  SendNotification,
  ReadNotification,
  CancelNotification,
  DelNotification,
  ReadRequest,
  DelRequest,
  DelResponse,
  CancelRequest,
  CancelResponse,
  EventJson
} from '@ucap-webmessenger/protocol-event';
import {
  InfoRequest as FileInfoRequest,
  InfoResponse as FileInfoResponse,
  FileDownloadInfo,
  FileInfo
} from '@ucap-webmessenger/protocol-file';

export const info = createAction(
  '[Messenger::Event] Info',
  props<InfoRequest>()
);
export const infoSuccess = createAction(
  '[Messenger::Event] Info Success',
  props<{
    infoList: Info<EventJson>[];
    res: InfoResponse;
    remainInfo: boolean;
  }>()
);
export const infoFailure = createAction(
  '[Messenger::Event] Info Failure',
  props<{ error: any }>()
);
export const infoForSearch = createAction(
  '[Messenger::Event] Info for search',
  props<{ req: InfoRequest; searchText?: string }>()
);
export const infoForSearchEnd = createAction(
  '[Messenger::Event] Info for search End',
  props()
);

export const infoAll = createAction(
  '[Messenger::Event] Info All',
  props<{ req: InfoRequest; infoList: Info<EventJson>[] }>()
);

export const fileInfo = createAction(
  '[Messenger::Event] File Info',
  props<{ req: FileInfoRequest }>()
);
export const fileInfoSuccess = createAction(
  '[Messenger::Event] File Info Success',
  props<{
    fileInfoList: FileInfo[];
    fileInfoCheckList: FileDownloadInfo[];
    res: FileInfoResponse;
  }>()
);
export const fileInfoFailure = createAction(
  '[Messenger::Event] File Info Failure',
  props<{ error: any }>()
);

export const infoMoreSuccess = createAction(
  '[Messenger::Event] Info More Success',
  props<{
    infoList: Info<EventJson>[];
    res: InfoResponse;
    remainInfo: boolean;
  }>()
);

export const infoIntervalClear = createAction(
  '[Messenger::Event] Info Interval Clear',
  props()
);

export const newInfo = createAction(
  '[Messenger::Event] New Info',
  props<{
    roomSeq: string;
    info: Info<EventJson>;
    SVC_TYPE?: number;
    SSVC_TYPE?: number;
  }>()
);

export const appendInfoList = createAction(
  '[Messenger::Event] Append InfoList',
  props<{
    info: Info<EventJson>;
  }>()
);

export const send = createAction(
  '[Messenger::Event] Send',
  props<{ senderSeq: number; req: SendRequest }>()
);

export const sendSuccess = createAction(
  '[Messenger::Event] Send Success',
  props<{
    senderSeq: number;
    res: SendResponse;
  }>()
);

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

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

export const forward = createAction(
  '[Messenger::Event] forward',
  props<{
    senderSeq: number;
    req: SendRequest;
    trgtUserSeqs?: number[];
    trgtRoomSeq?: string;
  }>()
);
export const forwardFailure = createAction(
  '[Messenger::Event] Forward Failure',
  props<{ error: any }>()
);
export const forwardAfterRoomOpen = createAction(
  '[Messenger::Event] forwardAfterRoomOpen',
  props<{
    senderSeq: number;
    req: SendRequest;
    trgtUserSeqs?: number[];
    trgtRoomSeq?: string;
  }>()
);
export const roomOpenAfterForward = createAction(
  '[Messenger::Event] roomOpenAfterForward',
  props<{
    senderSeq: number;
    req: SendRequest;
    trgtUserSeqs?: number[];
    trgtRoomSeq?: string;
  }>()
);

export const sendMass = createAction(
  '[Messenger::Event] Send Mass',
  props<{ senderSeq: number; req: SendRequest }>()
);
export const sendMassSuccess = createAction(
  '[Messenger::Event] Send Mass Success',
  props<{
    senderSeq: number;
    res: SendResponse;
  }>()
);
export const sendMassFailure = createAction(
  '[Messenger::Event] Send Mass Failure',
  props<{ error: any }>()
);

export const read = createAction(
  '[Messenger::Event] read',
  props<ReadRequest>()
);

export const readSuccess = createAction(
  '[Messenger::Event] read Success',
  props<{
    infoList: Info<EventJson>[];
    res: InfoResponse;
  }>()
);

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

export const readNotification = createAction(
  '[Messenger::Event] Read Notification',
  props<ReadNotification>()
);

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

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