import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
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.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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

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

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

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

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

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