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

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

export namespace MenuApi {
  export interface PageParams {
    title?: string;
    type?: number;
  }

  export interface BasicRecordItem {
    title: string;
    icon: string;
    permission: string;
    path: string;
    component: string;
    sort: number;
    status: number;
    meta: any;
  }

  export interface RecordItem extends BasicRecordItem {
    id: number;
  }

  export const getList = (params: PageParams) =>
    requestClient.get<RecordItem[]>('/menu/list', { params });

  export const getTree = () =>
    requestClient.get<BasicTreeOptionResult[]>('/menu/tree');

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

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

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

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