import BasicService from './BasicService';

/**
 * @desc 字典服务
 */
class DictionaryService extends BasicService {
  constructor() {
    super();
  }

  /**
   * 参数类型:参数类别查询
   * @param data
   * @returns
   */
  queryDictionaryPage = async (data: any) => {
    const { page, size, sort, ...dto } = data;
    return await this.post(
      `/gateway/idm/api/idm-dictionarys/queryDictionaryPage?page=${page}&size=${size}&sort=${sort}`,
      dto,
    );
  };

  /**
   * 参数类型:参数类别信息的修改
   * @param data
   * @returns
   */
  saveDictionary = async (data: any) => {
    return await this.post(
      `/gateway/idm/api/idm-dictionarys/saveDictionary`,
      data,
    );
  };

  /**
   * 参数类型:删除参数类
   * @param data
   * @returns
   */
  deleteDictionaryById = async (ids: string) => {
    return await this.post(
      `/gateway/idm/api/idm-dictionarys/deleteDictionaryById/${ids}`,
    );
  };

  /**
   * 选项配置:删除参数类
   * @param data
   * @returns
   */
  deleteDictionaryValueByIds = async (ids: string) => {
    return await this.post(
      `/gateway/idm/api/idm-dictionarys/deleteDictionaryValueByIds/${ids}`,
    );
  };

  /**
   * 参数类型:是否启用字典,T/F
   * @param data
   * @returns
   */
  changeDictionaryStatus = async (id: string, flag: string) => {
    return await this.post(
      `/gateway/idm/api/idm-dictionarys/changeDictionaryStatus/${id}/${flag}`,
    );
  };

  /**
   * 参数类型:根据ID返回字典
   * @param data
   * @returns
   */
  getIdmDictionaryById = async (id: string) => {
    return await this.get(
      `/gateway/idm/api/idm-dictionarys/getIdmDictionaryById/${id}`,
    );
  };

  /**
   * 参数类别信息的修改
   * @param data
   * @returns
   */
  saveDictionaryValueBatch = async (data: any) => {
    return await this.post(
      `/gateway/idm/api/idm-dictionarys/saveDictionaryValueBatch`,
      data,
    );
  };

  /**
   * 参数类别信息的修改(单个)
   * @param data
   * @returns
   */
  saveDictionaryValue = async (data: any) => {
    return await this.post(
      `/gateway/idm/api/idm-dictionarys/saveDictionaryValue`,
      data,
    );
  };

  /**
   * 字典选项配置查询
   * @param data
   * @returns
   */
  queryDictionaryValuePage = async (data: any) => {
    const { page, size, sort, ...dto } = data;
    return await this.post(
      `/gateway/idm/api/idm-dictionarys/queryDictionaryValuePage?page=${page}&size=${size}&sort=${sort}`,
      dto,
    );
  };

  /**
   * 获取地区信息
   * @param data
   * @returns
   */
  countryType = async () => {
    return await this.get(
      `/gateway/idm/api/idm-dictionarys/getTopDictionaryModelByCode/countryType`,
    );
  };

  /**
   * 获取父级地区信息
   */
  getChildDictionaryModelByParentId = async (code: string) => {
    return await this.get(
      `/gateway/idm/api/idm-dictionarys/getChildDictionaryModelByParentId/${code}`,
    );
  };

  /**
   * 获取字数据
   */
  getDictionaryByCode = async (code: string) => {
    return await this.get(
      `/gateway/idm/api/idm-dictionarys/getDictionaryByCode/${code}`,
    );
  };
}

const dictionaryService = new DictionaryService();

export default dictionaryService;
