import request, { downloadExcelRequest } from '../utils/request';
import { Result, ResultList, _Pager_Params } from './types';

// 床位
export interface BedFields {
  searchValue: string;
  createBy: string;
  createTime: string;
  updateBy: string;
  updateTime: string;
  remark: string;
  params: Record<string, any>;
  orgCode: string;
  orgName: string;
  deptCode: string;
  deptName: string;
  bedCode: string;
  bedNo: string;
  bedClass: string;
  bedStatus: string;
  version: string;
  createrUuid: string;
  updaterUuid: string;
  createDate: string;
  updateDate: string;
}

// 列表
interface GetList_Params extends _Pager_Params, BedFields {}

type ListResult = ResultList<BedFields[]>;

/** @name 床位列表 */
export async function getListApi(params: Partial<GetList_Params>) {
  return request<Partial<ListResult>>({
    url: '/bed/list',
    method: 'get',
    params,
  });
}

// 新增
type _Add_Params = Partial<BedFields>;
export async function addApi(data: _Add_Params) {
  return request({
    url: '/bed',
    method: 'post',
    data,
  });
}
// 编辑
type _Update_Params = Partial<BedFields>;
export async function updateApi(data: _Update_Params) {
  return request({
    url: '/bed/edit',
    method: 'post',
    data,
  });
}

export async function importBedApi(data: FormData): Promise<Result> {
  return request({
    url: '/bed/import',
    method: 'post',
    data,
  });
}

/**@name 批量操作 */
interface BedProps {
  orgCode: string;
  deptCode: string;
  bedCode: string;
}
interface BatchProps {
  beds: BedProps[];
  bedStatus: string;
}
export async function batchApi(data: BatchProps) {
  return request<Result>({
    url: '/bed/batch',
    method: 'post',
    data,
  });
}

/**
 * @name 批量删除
 */
export async function delApi(data: BedProps[]) {
  return request({
    url: `/bed/delete`,
    method: 'post',
    data,
  });
}

export async function exportDedApi() {
  return downloadExcelRequest(
    {
      url: '/bed/export',
      params: { tempOnly: 1 },
      method: 'post',
    },
    '床位模板',
  );
}
