import { v4 as getUUID } from 'uuid';
import request, { downloadExcelRequest } from '../utils/request';
import { ResultList, _Pager_Params } from './types';
// 科室
export interface DeptFields {
  insSupDeptCode: string;
  wardCode: string;
  deptOpenDate: string;
  deptName: string;
  orgName: string;
  deptDesc: string;
  deptStatus: string;
  orgCode: string;
  deptCode: string;
  insDeptCode: string;
  satDeptCode: string;
  deptAddress: string;
  deptPhone: string;
  subNum: number;
  wardName: string;
  uuid: string;
  staDeptCode: string;
  version: string;
}
// 列表
interface GetList_Params extends _Pager_Params {
  deptName: string;
  orgCode: string;
  deptStatus?: string;
}

export async function getListApi(params: Partial<GetList_Params>) {
  return request<ResultList>({
    url: '/department/list',
    method: 'get',
    params,
  });
}

// 详情
export async function getDetailsApi(data: _Add_Params) {
  return request<Partial<ResultList>>({
    url: `/department`,
    method: 'get',
    params: data,
  });
}

// 新增
type _Add_Params = Partial<DeptFields>;
export async function addApi(data: _Add_Params) {
  return request<Partial<ResultList>>({
    url: '/department',
    method: 'post',
    data,
  });
}
// 编辑
type _Update_Params = Partial<DeptFields>;
export async function updateApi(data: _Update_Params) {
  return request<Partial<ResultList>>({
    url: '/department/edit',
    method: 'post',
    data: { ...data, UPDATER_UUID: getUUID() },
  });
}
// 批量删除
type del_type = {
  orgCode: string;
  deptCode: string;
};
export async function delApi(data: del_type[]) {
  return request({
    url: '/department/delete',
    method: 'post',
    data,
  });
}

export async function importDeptApi(data: FormData) {
  return request({
    url: '/department/import',
    method: 'post',
    data,
  });
}

type param_type = {
  deptStatus: string;
  depts: any[];
};
/**
 * @name 审批
 * @param data
 * @returns
 */
export async function batchApi(data: param_type) {
  return request({
    url: '/department/batch',
    method: 'post',
    data,
  });
}

export async function exportDeptApi() {
  return downloadExcelRequest(
    {
      url: '/department/export',
      params: { tempOnly: 1 },
      method: 'post',
    },
    '科室模板',
  );
}
