import {
  APIRequest,
  MessageAPIResponse,
  APIDecoder,
  APIJsonEncoder
} from '@ucap-webmessenger/api';
import { DeviceType } from '@ucap-webmessenger/core';
import { MessageType } from '../types/message.type';
import { CategoryType } from '../types/category.type';

export interface DetailRequest extends APIRequest {
  userSeq: number;
  deviceType: DeviceType;
  tokenKey: string;
  type: MessageType;

  msgId: number;
}

export interface DetailResponse extends MessageAPIResponse {
  msgInfo: {
    msgId: number;
    category: CategoryType;
    title: string;
    titleYn: boolean;
  };

  content: {
    type: MessageType;
    sendUserSeq: number;
    sendUserName: string;
    reservationTime: string | null;
    sendYn: boolean;
    regDate: string;
    attachmentYn: boolean;
    smsYn: boolean;
    fileAllow: string;
  }[];

  recvList: {
    userSeq: number;
    userName: string;
    cancelYn: boolean;
    readDate: string;
    readYn: boolean;
  }[];
}

export const encodeDetail: APIJsonEncoder<DetailRequest> = (
  req: DetailRequest
) => {
  return JSON.stringify(req);
};

export const decodeDetail: APIDecoder<DetailResponse> = (res: any) => {
  return {
    responseCode: res.responseCode,
    responseMsg: res.responseMsg,

    msgInfo: null,

    content: [],

    recvList: []
  } as DetailResponse;
};

export interface ReadRequest extends APIRequest {
  userSeq: number;
  deviceType: DeviceType;
  tokenKey: string;
  type: MessageType;

  msgId: number;
}

export interface ReadResponse extends MessageAPIResponse {}

export const encodeRead: APIJsonEncoder<ReadRequest> = (req: ReadRequest) => {
  return JSON.stringify(req);
};

export const decodeRead: APIDecoder<ReadResponse> = (res: any) => {
  return {
    responseCode: res.responseCode,
    responseMsg: res.responseMsg
  } as ReadResponse;
};

export interface ReadCheckResponse extends MessageAPIResponse {
  recvList: {
    userSeq: number;
    userName: string;
    cancelYn: boolean;
    readDate: string;
    readYn: boolean;
  }[];
}

export const decodeReadCheck: APIDecoder<ReadCheckResponse> = (res: any) => {
  return {
    responseCode: res.responseCode,
    responseMsg: res.responseMsg,

    recvList: []
  } as ReadCheckResponse;
};

export interface CancelRequest extends APIRequest {
  userSeq: number;
  deviceType: DeviceType;
  tokenKey: string;
  type: MessageType;

  msgId: number;
  recvUserList: { userSeq: number }[];
}

export interface CancelResponse extends MessageAPIResponse {}

export const encodeCancel: APIJsonEncoder<CancelRequest> = (
  req: CancelRequest
) => {
  return JSON.stringify(req);
};

export const decodeCancel: APIDecoder<CancelResponse> = (res: any) => {
  return {
    responseCode: res.responseCode,
    responseMsg: res.responseMsg
  } as CancelResponse;
};

export interface CancelReservationRequest extends APIRequest {
  userSeq: number;
  deviceType: DeviceType;
  tokenKey: string;
  type: MessageType;

  msgId: number;
}

export interface CancelReservationResponse extends MessageAPIResponse {}

export const encodeCancelReservation: APIJsonEncoder<CancelReservationRequest> = (
  req: CancelReservationRequest
) => {
  return JSON.stringify(req);
};

export const decodeCancelReservation: APIDecoder<CancelReservationResponse> = (
  res: any
) => {
  return {
    responseCode: res.responseCode,
    responseMsg: res.responseMsg
  } as CancelReservationResponse;
};

export interface RetrieveResourceFileRequest extends APIRequest {
  userSeq: number;
  deviceType: DeviceType;
  tokenKey: string;
  type: MessageType;

  msgId: number;
  resUrl: string;
}

export interface RetrieveResourceFileResponse extends MessageAPIResponse {}

export const encodeRetrieveResourceFile: APIJsonEncoder<RetrieveResourceFileRequest> = (
  req: RetrieveResourceFileRequest
) => {
  return JSON.stringify(req);
};

export const decodeRetrieveResourceFile: APIDecoder<RetrieveResourceFileResponse> = (
  res: any
) => {
  return {} as RetrieveResourceFileResponse;
};
