<?php

namespace App\Http\Controllers\Api\V1;

use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Services\Authz\UserRoleService;
use Illuminate\Http\Request;

class UserRoleController extends Controller
{
    public function index($id)
    {
        return ApiResponse::handle(function () use ($id) {
            return UserRoleService::list((int) $id);
        }, '사용자의 역할 목록 조회');
    }

    public function grant($id, Request $request)
    {
        return ApiResponse::handle(function () use ($id, $request) {
            return UserRoleService::grant((int) $id, $request->all());
        }, '사용자에게 역할 부여');
    }

    public function revoke($id, Request $request)
    {
        return ApiResponse::handle(function () use ($id, $request) {
            return UserRoleService::revoke((int) $id, $request->all());
        }, '사용자의 역할 회수');
    }

    public function sync($id, Request $request)
    {
        return ApiResponse::handle(function () use ($id, $request) {
            return UserRoleService::sync((int) $id, $request->all());
        }, '사용자의 역할 동기화');
    }
}
