import httpClient from '@/utils/http';

import {
  ControllerResponse,
  ModelCreateSysMenuRequest,
  ModelSysMenu,
  ModelUpdateSysMenuRequest
} from './data-contracts';
export default {
  /**
   * @description 创建新的菜单
   */
  menusCreate: (menu: ModelCreateSysMenuRequest) => {
    return httpClient.post<
      ControllerResponse & {
        /** 系统菜单信息模型 */
        data?: ModelSysMenu;
      }
    >(`/sys/menus`, { params: menu });
  },
  /**
   * @description 获取所有菜单的列表信息
   */
  menusList: (query: {
    /**
     * 页码
     * @default 1
     */
    page?: number;
    /**
     * 每页数量
     * @default 10
     */
    page_size?: number;
  }) => {
    return httpClient.get<
      ControllerResponse & {
        data?: {
          menus?: ModelSysMenu[];
          pagination?: {
            limit?: number;
            page?: number;
            total?: number;
          };
        };
      }
    >(`/sys/menus`, { query: query });
  },
  /**
   * @description 根据父级菜单ID获取子菜单列表
   */
  menusChildrenList: (query: {
    /** 父级菜单ID */
    parent_id: string;
  }) => {
    return httpClient.get<
      ControllerResponse & {
        data?: ModelSysMenu[];
      }
    >(`/sys/menus/children`, { query: query });
  },
  /**
   * @description 获取菜单的树形结构
   */
  menusTreeList: () => {
    return httpClient.get<
      ControllerResponse & {
        data?: ModelSysMenu[];
      }
    >(`/sys/menus/tree`);
  },
  /**
   * @description 根据菜单ID获取特定菜单的详细信息
   */
  menusDetail: (id: number) => {
    return httpClient.get<
      ControllerResponse & {
        /** 系统菜单信息模型 */
        data?: ModelSysMenu;
      }
    >(`/sys/menus/${id}`);
  },
  /**
   * @description 根据ID更新菜单信息
   */
  menusUpdate: (id: string, menu: ModelUpdateSysMenuRequest) => {
    return httpClient.put<
      ControllerResponse & {
        /** 系统菜单信息模型 */
        data?: ModelSysMenu;
      }
    >(`/sys/menus/${id}`, { params: menu });
  },
  /**
   * @description 根据ID删除菜单（软删除）
   */
  menusDelete: (id: number) => {
    return httpClient.delete<
      ControllerResponse & {
        data?: string;
      }
    >(`/sys/menus/${id}`);
  },
  /**
   * @description 移除指定角色的菜单权限，menu_ids为逗号分割字符串
   */
  rolesMenusDelete: (
    roleId: number,
    query: {
      /** 菜单ID列表，逗号分隔 */
      menu_ids: string;
    }
  ) => {
    return httpClient.delete<
      ControllerResponse & {
        data?: string;
      }
    >(`/sys/roles/${roleId}/menus`, { query: query });
  }
};
