<?php
declare (strict_types=1);

namespace app\controller;

use app\BaseController;
use app\service\MenuService;
use app\service\PermissionService;

class Menu extends BaseController
{
    /**
     * 获取用户菜单列表
     */
    public function getUserMenus()
    {
        try {
            $menus = MenuService::getMenuTree($this->userId);
            return json_success($menus);
        } catch (\Exception $e) {
            return json_error('获取菜单失败：' . $e->getMessage());
        }
    }

    /**
     * 获取所有权限配置（用于角色权限分配）
     */
    public function getAllPermissions()
    {
        try {
            $permissions = PermissionService::getAllPermissions();
            return json_success($permissions);
        } catch (\Exception $e) {
            return json_error([], '获取权限配置失败：' . $e->getMessage());
        }
    }
}