"""
角色管理 API 客户端
"""

from httpx import AsyncClient


class RoleAPI:
    """角色管理 API 客户端"""
    
    def __init__(self, client: AsyncClient):
        self.client = client
    
    async def get_role_list(self):
        """获取角色列表"""
        return await self.client.get('/api/roles')
    
    async def get_role_by_id(self, role_id):
        """根据ID获取角色"""
        return await self.client.get(f'/api/roles/{role_id}')
    
    async def create_role(self, role_data):
        """创建角色"""
        return await self.client.post('/api/roles', json=role_data)
    
    async def update_role(self, role_id, role_data):
        """更新角色"""
        return await self.client.put(f'/api/roles/{role_id}', json=role_data)
    
    async def delete_role(self, role_id):
        """删除角色"""
        return await self.client.delete(f'/api/roles/{role_id}')
    
    async def get_role_permissions(self, role_id):
        """获取角色权限"""
        return await self.client.get(f'/api/roles/{role_id}/permissions')
    
    async def assign_permissions(self, role_id, permission_ids):
        """分配权限"""
        return await self.client.post(f'/api/roles/{role_id}/permissions', json={"permissionIds": permission_ids})
    
    async def assign_menus(self, role_id, menu_ids):
        """分配菜单权限（权限分配的别名）"""
        return await self.assign_permissions(role_id, menu_ids)
    
    async def get_user_menus_by_role(self, role_id):
        """获取角色菜单（别名方法）"""
        return await self.client.get(f'/api/menus/role/{role_id}')
