import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api/index';
import type { ClinicMedicineInout, ClinicMedicineInoutParam } from './model';

/**
 * 分页查询出入库
 */
export async function pageClinicMedicineInout(params: ClinicMedicineInoutParam) {
  const res = await request.get<ApiResult<PageResult<ClinicMedicineInout>>>(
    '/clinic/clinic-medicine-inout/page',
    params
  );
  if (res.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 查询出入库列表
 */
export async function listClinicMedicineInout(params?: ClinicMedicineInoutParam) {
  const res = await request.get<ApiResult<ClinicMedicineInout[]>>(
    '/clinic/clinic-medicine-inout',
    params
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 添加出入库
 */
export async function addClinicMedicineInout(data: ClinicMedicineInout) {
  const res = await request.post<ApiResult<unknown>>(
    '/clinic/clinic-medicine-inout',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 修改出入库
 */
export async function updateClinicMedicineInout(data: ClinicMedicineInout) {
  const res = await request.put<ApiResult<unknown>>(
    '/clinic/clinic-medicine-inout',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 删除出入库
 */
export async function removeClinicMedicineInout(id?: number) {
  const res = await request.del<ApiResult<unknown>>(
    '/clinic/clinic-medicine-inout/' + id
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 批量删除出入库
 */
export async function removeBatchClinicMedicineInout(data: (number | undefined)[]) {
  const res = await request.del<ApiResult<unknown>>(
    '/clinic/clinic-medicine-inout/batch',
    {
      data
    }
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 根据id查询出入库
 */
export async function getClinicMedicineInout(id: number) {
  const res = await request.get<ApiResult<ClinicMedicineInout>>(
    '/clinic/clinic-medicine-inout/' + id
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}
