<?php

namespace App\Controllers\Panel;

use App\Controllers\BaseController;

class PanelController extends BaseController
{
    protected function panelData(array $extra = []): array
    {
        $user = $this->currentUser();
        return array_merge([
            'userName' => $user->name,
            'role'     => $user->role_slug,
            'photoUrl' => $user->profile_photo_path ? base_url($user->profile_photo_path) : null,
        ], $extra);
    }

    protected function requireAgency(): void
    {
        $user = $this->currentUser();
        if (! in_array($user->role_slug, ['agency_owner', 'recruiter', 'support_staff'], true)) {
            throw new \App\Exceptions\ForbiddenException('This page is only available to agency accounts.');
        }
    }

    protected function requireCandidate(): void
    {
        if (! $this->currentUser()->isCandidate()) {
            throw new \App\Exceptions\ForbiddenException('This page is only available to candidate accounts.');
        }
    }

    protected function requireSuperAdmin(): void
    {
        if (! $this->currentUser()->isSuperAdmin()) {
            throw new \App\Exceptions\ForbiddenException('This page is only available to platform administrators.');
        }
    }
}
