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

/**
 * 分页查询计算机软件著作权登记
 */
export async function pageOaAssetsSoftwareCert(params: OaAssetsSoftwareCertParam) {
  const res = await request.get<ApiResult<PageResult<OaAssetsSoftwareCert>>>(
    '/oa/oa-assets-software-cert/page',
    {
      params
    }
  );
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询计算机软件著作权登记列表
 */
export async function listOaAssetsSoftwareCert(params?: OaAssetsSoftwareCertParam) {
  const res = await request.get<ApiResult<OaAssetsSoftwareCert[]>>(
    '/oa/oa-assets-software-cert',
    {
      params
    }
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加计算机软件著作权登记
 */
export async function addOaAssetsSoftwareCert(data: OaAssetsSoftwareCert) {
  const res = await request.post<ApiResult<unknown>>(
    '/oa/oa-assets-software-cert',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改计算机软件著作权登记
 */
export async function updateOaAssetsSoftwareCert(data: OaAssetsSoftwareCert) {
  const res = await request.put<ApiResult<unknown>>(
    '/oa/oa-assets-software-cert',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除计算机软件著作权登记
 */
export async function removeOaAssetsSoftwareCert(id?: number) {
  const res = await request.delete<ApiResult<unknown>>(
    '/oa/oa-assets-software-cert/' + id
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 批量删除计算机软件著作权登记
 */
export async function removeBatchOaAssetsSoftwareCert(data: (number | undefined)[]) {
  const res = await request.delete<ApiResult<unknown>>(
    '/oa/oa-assets-software-cert/batch',
    {
      data
    }
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询计算机软件著作权登记
 */
export async function getOaAssetsSoftwareCert(id: number) {
  const res = await request.get<ApiResult<OaAssetsSoftwareCert>>(
    '/oa/oa-assets-software-cert/' + id
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
