<?php

namespace App\Providers;

use App\Listeners\GiveBonusCredits;
use App\Models\Event;
use App\Observers\EventObserver;
use Illuminate\Support\Facades\Event as FacadesEvent;
use Illuminate\Auth\Events\Registered;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        if (app()->environment('production')) {
            URL::forceScheme('https');
        }

        FacadesEvent::listen(Registered::class, GiveBonusCredits::class);

        Event::observe(EventObserver::class);

        Blade::component('emails.components.code', 'mail.code');
        Blade::component('emails.components.button', 'mail.button');
        Blade::component('layouts.blank', 'layouts.blank');

        // Rollen-basierte Gates
        Gate::define('access-admin', fn($user) => $user->hasAtLeastRole('support'));
        Gate::define('manage-users', fn($user) => $user->isAdmin());
        Gate::define('give-credits', fn($user) => $user->isAdmin());
        Gate::define('gift-access', fn($user) => $user->isAdmin());
        Gate::define('view-technical-logs', fn($user) => $user->isDeveloper());
        Gate::define('change-roles', fn($user) => $user->isSuperAdmin());
        Gate::define('manage-affiliates', fn($user) => $user->isAdmin());
    }
}
