<?php

namespace App\Http\Controllers;

use App\Services\PermissionAnalyzeService;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\View\View;

class PermissionAnalyzeController extends Controller
{
    public function __construct(
        private PermissionAnalyzeService $service
    ) {}

    /**
     * 권한 분석 페이지
     * HTMX 요청 시 전체 페이지 리로드 (스크립트 로딩을 위해)
     */
    public function index(Request $request): View|Response
    {
        if ($request->header('HX-Request')) {
            return response('', 200)->header('HX-Redirect', route('permission-analyze.index'));
        }

        $tenantId = session('selected_tenant_id');
        $menuTree = $this->service->getMenuTree($tenantId);
        $permissionTypes = $this->service->getPermissionTypes();

        return view('permission-analyze.index', [
            'menuTree' => $menuTree,
            'permissionTypes' => $permissionTypes,
        ]);
    }
}
