import httpClient from '@/utils/http';

import {
  ControllerCreateDictionaryItemRequest,
  ControllerResponse,
  ControllerUpdateDictionaryItemRequest,
  ModelDictionaryItem
} from './data-contracts';
export default {
  /**
   * @description 创建新的数据字典项
   */
  itemsCreate: (item: ControllerCreateDictionaryItemRequest) => {
    return httpClient.post<
      ControllerResponse & {
        data?: ModelDictionaryItem;
      }
    >(`/dictionary/items`, { params: item });
  },
  /**
   * @description 根据code获取字典项列表，当code=class时，通过调用者所在学校以及grade_key来获取班级列表
   */
  itemsList: (query: {
    /** 字典类型编码 */
    code: string;
    /** 父级KEY */
    parent_key?: string;
  }) => {
    return httpClient.get<
      ControllerResponse & {
        data?: ModelDictionaryItem[];
      }
    >(`/dictionary/items`, { query: query });
  },
  /**
   * @description 根据ID获取字典项详情
   */
  itemsDetail: (id: number) => {
    return httpClient.get<
      ControllerResponse & {
        data?: ModelDictionaryItem;
      }
    >(`/dictionary/items/${id}`);
  },
  /**
   * @description 根据ID更新数据字典项
   */
  itemsUpdate: (id: number, item: ControllerUpdateDictionaryItemRequest) => {
    return httpClient.put<
      ControllerResponse & {
        data?: ModelDictionaryItem;
      }
    >(`/dictionary/items/${id}`, { params: item });
  },
  /**
   * @description 根据ID删除数据字典项
   */
  itemsDelete: (id: number) => {
    return httpClient.delete<
      ControllerResponse & {
        data?: string;
      }
    >(`/dictionary/items/${id}`);
  }
};
