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

/**
 * 分页查询商标注册
 */
export async function pageOaAssetsTrademark(params: OaAssetsTrademarkParam) {
  const res = await request.get<ApiResult<PageResult<OaAssetsTrademark>>>(
    '/oa/oa-assets-trademark/page',
    {
      params
    }
  );
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询商标注册列表
 */
export async function listOaAssetsTrademark(params?: OaAssetsTrademarkParam) {
  const res = await request.get<ApiResult<OaAssetsTrademark[]>>(
    '/oa/oa-assets-trademark',
    {
      params
    }
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加商标注册
 */
export async function addOaAssetsTrademark(data: OaAssetsTrademark) {
  const res = await request.post<ApiResult<unknown>>(
    '/oa/oa-assets-trademark',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改商标注册
 */
export async function updateOaAssetsTrademark(data: OaAssetsTrademark) {
  const res = await request.put<ApiResult<unknown>>(
    '/oa/oa-assets-trademark',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除商标注册
 */
export async function removeOaAssetsTrademark(id?: number) {
  const res = await request.delete<ApiResult<unknown>>(
    '/oa/oa-assets-trademark/' + id
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 批量删除商标注册
 */
export async function removeBatchOaAssetsTrademark(data: (number | undefined)[]) {
  const res = await request.delete<ApiResult<unknown>>(
    '/oa/oa-assets-trademark/batch',
    {
      data
    }
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询商标注册
 */
export async function getOaAssetsTrademark(id: number) {
  const res = await request.get<ApiResult<OaAssetsTrademark>>(
    '/oa/oa-assets-trademark/' + id
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
