import {
  APIRequest,
  MessageAPIResponse,
  APIJsonEncoder,
  APIDecoder
} from '@ucap-webmessenger/api';
import { DeviceType } from '@ucap-webmessenger/core';

export interface SaveMyRequest extends APIRequest {
  userSeq: number;
  deviceType: DeviceType;
  tokenKey: string;
  userName: string;
  message: string;
}

export interface SaveMyResponse extends MessageAPIResponse {}

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

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

export interface RetrieveMyRequest extends APIRequest {
  userSeq: number;
  deviceType: DeviceType;
  tokenKey: string;
  pageSize: number;
  pageCount: number;
}

export interface RetrieveMyResponse extends MessageAPIResponse {
  msgList: {
    msgId: number;
    message: string;
  }[];
}

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

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

    msgList: []
  } as RetrieveMyResponse;
};

export interface DelMyRequest extends APIRequest {
  userSeq: number;
  deviceType: DeviceType;
  tokenKey: string;
}

export interface DelMyResponse extends MessageAPIResponse {}

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

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

export interface EditMyRequest extends APIRequest {
  userSeq: number;
  deviceType: DeviceType;
  tokenKey: string;
  msgId: number;
  message: string;
}

export interface EditMyResponse extends MessageAPIResponse {}

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

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