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

/**
 * 分页查询黄家明_保险记录
 */
export async function pageHjmBxLog(params: HjmBxLogParam) {
  const res = await request.get<ApiResult<PageResult<HjmBxLog>>>(
    '/hjm/hjm-bx-log/page',
    params
  );
  if (res.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 查询黄家明_保险记录列表
 */
export async function listHjmBxLog(params?: HjmBxLogParam) {
  const res = await request.get<ApiResult<HjmBxLog[]>>(
    '/hjm/hjm-bx-log',
    params
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 添加黄家明_保险记录
 */
export async function addHjmBxLog(data: HjmBxLog) {
  const res = await request.post<ApiResult<unknown>>(
    '/hjm/hjm-bx-log',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 修改黄家明_保险记录
 */
export async function updateHjmBxLog(data: HjmBxLog) {
  const res = await request.put<ApiResult<unknown>>(
    '/hjm/hjm-bx-log',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 删除黄家明_保险记录
 */
export async function removeHjmBxLog(id?: number) {
  const res = await request.del<ApiResult<unknown>>(
    '/hjm/hjm-bx-log/' + id
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 批量删除黄家明_保险记录
 */
export async function removeBatchHjmBxLog(data: (number | undefined)[]) {
  const res = await request.del<ApiResult<unknown>>(
    '/hjm/hjm-bx-log/batch',
    {
      data
    }
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 根据id查询黄家明_保险记录
 */
export async function getHjmBxLog(id: number) {
  const res = await request.get<ApiResult<HjmBxLog>>(
    '/hjm/hjm-bx-log/' + id
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}
