<?php
// +----------------------------------------------------------------------
// | onezan-admin 快速开发的管理平台
// +----------------------------------------------------------------------
// | 官方网址：https://www.onezan.cn
// +----------------------------------------------------------------------
// | onezan团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: 543885307@qq.com
// +----------------------------------------------------------------------
namespace app\adminapi\controller\admin;

use app\adminapi\controller\BaseAdminController;
use app\service\admin\admin\RoleService;
use think\Request;


/**
 * 角色管理
 * 角色 CRUD 及权限分配
 * @package app\adminapi\controller\admin
 */
class Role extends BaseAdminController
{
    /**
     * 角色权限分配
     * @param Request $request
     * @return \think\response\Json
     */
    public function permissions(Request $request)
    {
        $result = $this->app->make(RoleService::class)->permissions($request);
        $httpStatus = (int)($result['_http_status'] ?? 200);
        unset($result['_http_status']);
        return json($result, $httpStatus);
    }

    /**
     * 角色列表
     * @param Request $request
     * @return \think\response\Json
     */
    public function list(Request $request)
    {
        return json($this->app->make(RoleService::class)->list($request));
    }

    /**
     * 保存角色
     * @param Request $request
     * @return \think\response\Json
     */
    public function save(Request $request)
    {
        $result = $this->app->make(RoleService::class)->save($request);
        $httpStatus = (int)($result['_http_status'] ?? 200);
        unset($result['_http_status']);
        return json($result, $httpStatus);
    }

    /**
     * 删除角色
     * @param Request $request
     * @return \think\response\Json
     */
    public function delete(Request $request)
    {
        return json($this->app->make(RoleService::class)->delete($request));
    }
}
