<?php

namespace App\Http\Controllers\Api\V1;

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

class RoleController extends Controller
{
    /**
     * 역할 목록 조회
     */
    public function index(Request $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return RoleService::index($request->all());
        }, __('message.fetched'));
    }

    /**
     * 역할 생성
     */
    public function store(Request $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return RoleService::store($request->all());
        }, __('message.created'));
    }

    /**
     * 역할 상세 조회
     */
    public function show($id)
    {
        return ApiResponse::handle(function () use ($id) {
            return RoleService::show((int) $id);
        }, __('message.fetched'));
    }

    /**
     * 역할 수정
     */
    public function update(Request $request, $id)
    {
        return ApiResponse::handle(function () use ($request, $id) {
            return RoleService::update((int) $id, $request->all());
        }, __('message.updated'));
    }

    /**
     * 역할 삭제
     */
    public function destroy($id)
    {
        return ApiResponse::handle(function () use ($id) {
            return RoleService::destroy((int) $id);
        }, __('message.deleted'));
    }

    /**
     * 역할 통계 조회
     */
    public function stats()
    {
        return ApiResponse::handle(function () {
            return RoleService::stats();
        }, __('message.fetched'));
    }

    /**
     * 활성 역할 목록 (드롭다운용)
     */
    public function active()
    {
        return ApiResponse::handle(function () {
            return RoleService::active();
        }, __('message.fetched'));
    }
}
