import type { BasicFetchResult, BasicPageParams } from '#/api/model';

import { requestClient } from '#/api/request';

export namespace ConfigApi {
  export interface PageParams extends BasicPageParams {
    name?: string;
    code?: string;
  }

  export interface BasicRecordItem {
    name: string;
    code: string;
  }

  export interface RecordItem extends BasicRecordItem {
    id: number;
  }

  export type PageResult = BasicFetchResult<RecordItem>;

  export const getPage = (params: PageParams) =>
    requestClient.get<PageResult>('/config/page', { params });

  export const getDetail = (id: number) =>
    requestClient.get<RecordItem>('/config/entity', {
      params: { id },
    });

  export const addDetail = (data: BasicRecordItem) =>
    requestClient.post('/config', data);

  export const editDetail = (data: RecordItem) =>
    requestClient.put('/config', data);

  export const deleteDetail = (id: number) =>
    requestClient.delete('/config', { data: { id } });
}
