/**
 * 权限相关 API - 匹配后端实际接口
 */

import { BaseService } from '../BaseService'
import type {
  Permission,
  PermissionTreeNode,
  CreatePermissionParams,
  UpdatePermissionParams,
  BaseResponse
} from '@/types/api'

export class PermissionService extends BaseService {
  /**
   * 获取权限树
   * GET /api/admin/permissions/tree
   * 用于角色分配权限时的树形选择
   */
  static getPermissionTree(): Promise<BaseResponse<PermissionTreeNode[]>> {
    return this.get<BaseResponse<PermissionTreeNode[]>>('/api/admin/permissions/tree')
  }

  /**
   * 获取权限详情
   * GET /api/admin/permissions/{id}
   * @param id 权限ID
   */
  static getPermission(id: number): Promise<BaseResponse<Permission>> {
    return this.getOne<Permission>(`/api/admin/permissions/${id}`)
  }

  /**
   * 创建权限
   * POST /api/admin/permissions
   * @param data 权限数据
   */
  static createPermission(data: CreatePermissionParams): Promise<BaseResponse> {
    return this.create('/api/admin/permissions', data)
  }

  /**
   * 更新权限
   * PUT /api/admin/permissions/{id}
   * @param id 权限ID
   * @param data 权限数据
   */
  static updatePermission(id: number, data: UpdatePermissionParams): Promise<BaseResponse> {
    return this.update(`/api/admin/permissions/${id}`, data)
  }

  /**
   * 删除权限
   * DELETE /api/admin/permissions/{id}
   * @param id 权限ID
   */
  static deletePermission(id: number): Promise<BaseResponse> {
    return this.remove(`/api/admin/permissions/${id}`)
  }
}
