import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
import type { OaTaskCount, OaTaskCountParam } from './model';

/**
 * 分页查询数据统计
 */
export async function pageOaTaskCount(params: OaTaskCountParam) {
  const res = await request.get<ApiResult<PageResult<OaTaskCount>>>(
    '/oa/oa-task-count/page',
    {
      params
    }
  );
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询数据统计列表
 */
export async function listOaTaskCount(params?: OaTaskCountParam) {
  const res = await request.get<ApiResult<OaTaskCount[]>>(
    '/oa/oa-task-count',
    {
      params
    }
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加数据统计
 */
export async function addOaTaskCount(data: OaTaskCount) {
  const res = await request.post<ApiResult<unknown>>(
    '/oa/oa-task-count',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改数据统计
 */
export async function updateOaTaskCount(data: OaTaskCount) {
  const res = await request.put<ApiResult<unknown>>(
    '/oa/oa-task-count',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除数据统计
 */
export async function removeOaTaskCount(id?: number) {
  const res = await request.delete<ApiResult<unknown>>(
    '/oa/oa-task-count/' + id
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 批量删除数据统计
 */
export async function removeBatchOaTaskCount(data: (number | undefined)[]) {
  const res = await request.delete<ApiResult<unknown>>(
    '/oa/oa-task-count/batch',
    {
      data
    }
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询数据统计
 */
export async function getOaTaskCount(id: number) {
  const res = await request.get<ApiResult<OaTaskCount>>(
    '/oa/oa-task-count/' + id
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
