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

/**
 * 分页查询企业邮箱记录表
 */
export async function pageOaAssetsEmail(params: OaAssetsEmailParam) {
  const res = await request.get<ApiResult<PageResult<OaAssetsEmail>>>(
    '/oa/oa-assets-email/page',
    {
      params
    }
  );
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询企业邮箱记录表列表
 */
export async function listOaAssetsEmail(params?: OaAssetsEmailParam) {
  const res = await request.get<ApiResult<OaAssetsEmail[]>>(
    '/oa/oa-assets-email',
    {
      params
    }
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加企业邮箱记录表
 */
export async function addOaAssetsEmail(data: OaAssetsEmail) {
  const res = await request.post<ApiResult<unknown>>(
    '/oa/oa-assets-email',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改企业邮箱记录表
 */
export async function updateOaAssetsEmail(data: OaAssetsEmail) {
  const res = await request.put<ApiResult<unknown>>(
    '/oa/oa-assets-email',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除企业邮箱记录表
 */
export async function removeOaAssetsEmail(id?: number) {
  const res = await request.delete<ApiResult<unknown>>(
    '/oa/oa-assets-email/' + id
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 批量删除企业邮箱记录表
 */
export async function removeBatchOaAssetsEmail(data: (number | undefined)[]) {
  const res = await request.delete<ApiResult<unknown>>(
    '/oa/oa-assets-email/batch',
    {
      data
    }
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询企业邮箱记录表
 */
export async function getOaAssetsEmail(id: number) {
  const res = await request.get<ApiResult<OaAssetsEmail>>(
    '/oa/oa-assets-email/' + id
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
