import { defHttp } from '/@/utils/http/axios';

import { ErrorMessageMode, Result } from '/#/axios';
import {
  ComplainCloseData,
  ComplainGetDownData,
  ComplaintsData,
  ComplaintsDetailParams,
  ComplaintsParams,
} from '/@/api/complaints/modal/complaintsModal';

enum Api {
  List = '/complain/list',
  Detail = '/complain/detail',
  Commit = '/complain/commit',
  GetDown = '/arbitrate/getDropdown',
  Logs = '/complain/logs',
  Close = '/complain/close',
  Nums = '/complain/nums',
}

/**
 * @description: 投诉列表
 */
export function complainListApi(data: ComplaintsParams, mode: ErrorMessageMode = 'message') {
  return defHttp.post<ComplaintsData[]>(
    {
      url: Api.List,
      data,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * @description: 处理投诉
 */
export function complainCommitApi(
  data: ComplaintsDetailParams,
  mode: ErrorMessageMode = 'message',
) {
  return defHttp.post<Result<undefined>>(
    {
      url: Api.Commit,
      data,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * @description: 投诉详情
 */
export function complainDetailApi(id: number, mode: ErrorMessageMode = 'message') {
  return defHttp.get<ComplaintsData>(
    {
      url: `${Api.Detail}/${id}`,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * @description: 获取投诉下拉框内容
 */
export function complainGetDownApi(data: any = {}, mode: ErrorMessageMode = 'message') {
  return defHttp.post<ComplainGetDownData>(
    {
      url: Api.GetDown,
      data,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * @description: 对应投诉的操作记录
 */
export function complainLogsApi(id: number, mode: ErrorMessageMode = 'message') {
  return defHttp.post<any>(
    {
      url: `${Api.Logs}/${id}`,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * @description: 关闭投诉
 */
export function complainCloseApi(id: number, mode: ErrorMessageMode = 'message') {
  return defHttp.post<ComplainCloseData[]>(
    {
      url: `${Api.Close}/${id}`,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * @description: 对应投诉的状态的数量
 */
export function complainNumsApi(_: any = undefined, mode: ErrorMessageMode = 'message') {
  return defHttp.post<any[]>(
    {
      url: Api.Nums,
    },
    {
      errorMessageMode: mode,
    },
  );
}
