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

/**
 * 分页查询医生入驻申请
 */
export async function pageClinicDoctorApply(params: ClinicDoctorApplyParam) {
  const res = await request.get<ApiResult<PageResult<ClinicDoctorApply>>>(
    '/clinic/clinic-doctor-apply/page',
    params
  );
  if (res.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 查询医生入驻申请列表
 */
export async function listClinicDoctorApply(params?: ClinicDoctorApplyParam) {
  const res = await request.get<ApiResult<ClinicDoctorApply[]>>(
    '/clinic/clinic-doctor-apply',
    params
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 添加医生入驻申请
 */
export async function addClinicDoctorApply(data: ClinicDoctorApply) {
  const res = await request.post<ApiResult<unknown>>(
    '/clinic/clinic-doctor-apply',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 修改医生入驻申请
 */
export async function updateClinicDoctorApply(data: ClinicDoctorApply) {
  const res = await request.put<ApiResult<unknown>>(
    '/clinic/clinic-doctor-apply',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 删除医生入驻申请
 */
export async function removeClinicDoctorApply(id?: number) {
  const res = await request.del<ApiResult<unknown>>(
    '/clinic/clinic-doctor-apply/' + id
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 批量删除医生入驻申请
 */
export async function removeBatchClinicDoctorApply(data: (number | undefined)[]) {
  const res = await request.del<ApiResult<unknown>>(
    '/clinic/clinic-doctor-apply/batch',
    {
      data
    }
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 根据id查询医生入驻申请
 */
export async function getClinicDoctorApply(id: number) {
  const res = await request.get<ApiResult<ClinicDoctorApply>>(
    '/clinic/clinic-doctor-apply/' + id
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}
