import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
import type { CmsWebsite, CmsWebsiteParam } from './model';
import {MODULES_API_URL} from '@/config/setting';

/**
 * 分页查询网站信息记录表
 */
export async function pageCmsWebsiteAll(params: CmsWebsiteParam) {
  const res = await request.get<ApiResult<PageResult<CmsWebsite>>>(
      MODULES_API_URL + '/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 listCmsWebsiteAll(params?: CmsWebsiteParam) {
  const res = await request.get<ApiResult<CmsWebsite[]>>(
    MODULES_API_URL + '/cms/cms-website/listAll',
    {
      params
    }
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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

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

export async function getCmsWebsiteAll(id: number){
  const res = await request.get<ApiResult<CmsWebsite>>(
    MODULES_API_URL + '/cms/cms-website/getAll/' + id
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
