import { get, post } from '@/api/request';

const env = import.meta.env;
const PREFIX = env.VITE_API_PREFIX_SYSTEM;

// 全量字典
export const getAllDictionaryDataApi = (params: any) => {
  return get(`${PREFIX}systemData/getAllDictionaryData`, params);
};

// 新增字典类
export const addDictionaryClassApi = (params: any) => {
  return post(`${PREFIX}systemData/addDictionaryClass`, params);
};

// 字典类列表
export const getDictionaryClassApi = (params: any) => {
  return get(`${PREFIX}systemData/getDictionaryClass`, params);
};

// 字典类详情
export const getDictionaryClassDetailApi = (params: any) => {
  return get(`${PREFIX}systemData/getDictionaryClassDetail`, params);
};

// 删除字典类
export const deleteDictionaryClassApi = (params: any) => {
  return get(`${PREFIX}systemData/deleteDictionaryClass`, params);
};

// 更新字典类
export const updateDictionaryClassApi = (params: any) => {
  return post(`${PREFIX}systemData/updateDictionaryClass`, params);
};

// 字典列表
export const getDictionaryDataApi = (params: any) => {
  return get(`${PREFIX}systemData/getDictionaryData`, params);
};

// 新增字典
export const addDictionaryDataApi = (params: any) => {
  return post(`${PREFIX}systemData/addDictionaryData`, params);
};

// 字典详情
export const getDictionaryDataDetailApi = (params: any) => {
  return get(`${PREFIX}systemData/getDictionaryDataDetail`, params);
};

// 删除字典
export const deleteDictionaryDataApi = (params: any) => {
  return get(`${PREFIX}systemData/deleteDictionaryData`, params);
};

// 更新字典
export const updateDictionaryDataApi = (params: any) => {
  return post(`${PREFIX}systemData/updateDictionaryData`, params);
};

// 设置表头
export const addFormConfigureApi = (params: any) => {
  return post(`${PREFIX}systemData/addFormConfigure`, params);
};

// 获取表头
const formConfigureData: any = {}; // 缓存表头数据
export const getFormConfigureApi = async (params: any) => {
  if (formConfigureData[params.formName]) {
    return formConfigureData[params.formName];
  }
  const res = await get(`${PREFIX}systemData/getFormConfigure`, params);
  formConfigureData[params.formName] = res;
  return res;
};

// 更新表头
export const updateFormConfigureApi = (params: any) => {
  return post(`${PREFIX}systemData/updateFormConfigure`, params);
};

// 表头列表
export const listFormConfigureApi = (params: any) => {
  return post(`${PREFIX}systemData/listFormConfigure`, params);
};

// 删除表头
export const deleteFormConfigureApi = (params: any) => {
  return post(`${PREFIX}systemData/deleteFormConfigure`, params);
};
