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


/**
 * 分页查询页面管理记录表
 */
export async function pageCmsDesign(params: CmsDesignParam) {
  const res = await request.get<ApiResult<PageResult<CmsDesign>>>(
    '/cms/cms-design/page',
    params
  );
  if (res.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 查询页面管理记录表列表
 */
export async function listCmsDesign(params?: CmsDesignParam) {
  const res = await request.get<ApiResult<CmsDesign[]>>(
    '/cms/cms-design',
    params
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 添加页面管理记录表
 */
export async function addCmsDesign(data: CmsDesign) {
  const res = await request.post<ApiResult<unknown>>(
    '/cms/cms-design',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 修改页面管理记录表
 */
export async function updateCmsDesign(data: CmsDesign) {
  const res = await request.put<ApiResult<unknown>>(
    '/cms/cms-design',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 删除页面管理记录表
 */
export async function removeCmsDesign(id?: number) {
  const res = await request.del<ApiResult<unknown>>(
    '/cms/cms-design/' + id
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 批量删除页面管理记录表
 */
export async function removeBatchCmsDesign(data: (number | undefined)[]) {
  const res = await request.del<ApiResult<unknown>>(
    '/cms/cms-design/batch',
    {
      data
    }
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 根据id查询页面管理记录表
 */
export async function getCmsDesign(id: number) {
  const res = await request.get<ApiResult<CmsDesign>>(
    '/cms/cms-design/' + id
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}
