import { DeviceType } from '@ucap-webmessenger/core';
import {
  APIRequest,
  APIEncoder,
  ParameterUtil,
  APIFormDataEncoder
} from '@ucap-webmessenger/api';
import { FileDownloadItem } from '../models/file-download-item';

export interface FileTalkDownloadRequest extends APIRequest {
  userSeq: number;
  deviceType: DeviceType;
  token: string;
  attachmentsSeq?: number;
  fileDownloadItem?: FileDownloadItem;
}

const fileTalkDownloadEncodeMap = {
  userSeq: 'p_user_seq',
  deviceType: 'p_device_type',
  token: 'p_token',
  attachmentsSeq: 'p_att_seq'
};

export const encodeFileTalkDownload: APIEncoder<FileTalkDownloadRequest> = (
  req: FileTalkDownloadRequest
) => {
  const extraParams: any = {};

  extraParams.userSeq = String(req.userSeq);
  extraParams.attachmentsSeq = String(req.attachmentsSeq);

  return ParameterUtil.encode(fileTalkDownloadEncodeMap, req, extraParams);
};

export const encodeFormDataFileTalkDownload: APIFormDataEncoder<
  FileTalkDownloadRequest
> = (req: FileTalkDownloadRequest) => {
  const extraParams: any = {};

  extraParams.userSeq = String(req.userSeq);
  extraParams.attachmentsSeq = String(req.attachmentsSeq);

  return ParameterUtil.encodeFormData(
    fileTalkDownloadEncodeMap,
    req,
    extraParams
  );
};
