<?php

declare(strict_types=1);

namespace App\Policies;

use App\Models\AcademyChallenge;
use App\Models\User;
use App\Services\Academy\AcademyAccessService;

class AcademyChallengePolicy
{
    public function before(?User $user): ?bool
    {
        if ($user?->isAdmin()) {
            return true;
        }

        return null;
    }

    public function view(?User $user, AcademyChallenge $challenge): bool
    {
        return app(AcademyAccessService::class)->canAccessChallenge($user, $challenge);
    }

    public function manage(User $user): bool
    {
        return $user->hasStaffAccess();
    }
}