import type { BasicTreeOptionResult } from '../model';

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

export namespace DepartmentApi {
  export interface PageParams {
    code?: string;
    name?: string;
    orgType?: string;
  }

  export interface BasicRecordItem {
    parentId: number;
    name: string;
    code: string;
    orgType: string;
  }

  export interface RecordItem extends BasicRecordItem {
    id: number;
  }

  export const getTree = (params: PageParams) =>
    requestClient.get<RecordItem[]>('/department/tree', { params });

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

  export const getTreeOptions = () =>
    requestClient.get<BasicTreeOptionResult[]>('/department/tree-options');

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

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

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