/**
 * 权限服务
 * 
 * 提供权限管理相关 API 调用
 */

import { get, post, put, del } from '@/lib/http/client'
import type { Permission, CreatePermissionRequest, UpdatePermissionRequest } from '@/types/permission'

/**
 * 获取权限树
 * GET /api/v1/permissions/tree
 */
export function getPermissionTree(): Promise<Permission[]> {
  return get<Permission[]>('/permissions/tree')
}

/**
 * 获取所有权限列表（扁平）
 * GET /api/v1/permissions
 */
export function listPermissions(): Promise<Permission[]> {
  return get<Permission[]>('/permissions')
}

/**
 * 获取权限详情
 * GET /api/v1/permissions/:id
 */
export function getPermission(id: number): Promise<Permission> {
  return get<Permission>(`/permissions/${id}`)
}

/**
 * 创建权限
 * POST /api/v1/permissions
 */
export function createPermission(data: CreatePermissionRequest): Promise<Permission> {
  return post<Permission>('/permissions', data)
}

/**
 * 更新权限
 * PUT /api/v1/permissions/:id
 */
export function updatePermission(id: number, data: UpdatePermissionRequest): Promise<Permission> {
  return put<Permission>(`/permissions/${id}`, data)
}

/**
 * 删除权限
 * DELETE /api/v1/permissions/:id
 */
export function deletePermission(id: number): Promise<void> {
  return del<void>(`/permissions/${id}`)
}

/**
 * 更新权限状态
 * PUT /api/v1/permissions/:id/status
 */
export function updatePermissionStatus(id: number, status: 0 | 1): Promise<void> {
  return put<void>(`/permissions/${id}/status`, { status })
}
