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

/**
 * 分页查询网站信息记录表
 */
export async function pageOaAssetsSite(params: OaAssetsSiteParam) {
  const res = await request.get<ApiResult<PageResult<OaAssetsSite>>>(
    '/cms/cms-website/pageAll',
    {
      params
    }
  );
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询网站信息记录表列表
 */
export async function listOaAssetsSite(params?: OaAssetsSiteParam) {
  const res = await request.get<ApiResult<OaAssetsSite[]>>(
    '/cms/cms-website',
    {
      params
    }
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加网站信息记录表
 */
export async function addOaAssetsSite(data: OaAssetsSite) {
  const res = await request.post<ApiResult<unknown>>(
    '/cms/cms-website',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改网站信息记录表
 */
export async function updateOaAssetsSite(data: OaAssetsSite) {
  const res = await request.put<ApiResult<unknown>>(
    '/cms/cms-website',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除网站信息记录表
 */
export async function removeOaAssetsSite(id?: number) {
  const res = await request.delete<ApiResult<unknown>>(
    '/cms/cms-website/' + id
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 批量删除网站信息记录表
 */
export async function removeBatchOaAssetsSite(data: (number | undefined)[]) {
  const res = await request.delete<ApiResult<unknown>>(
    '/cms/cms-website/batch',
    {
      data
    }
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询网站信息记录表
 */
export async function getOaAssetsSite(id: number) {
  const res = await request.get<ApiResult<OaAssetsSite>>(
    '/cms/cms-website/' + id
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
