<?php

namespace App\Providers;

use Dedoc\Scramble\Scramble;
use Dedoc\Scramble\Support\Generator\OpenApi;
use Dedoc\Scramble\Support\Generator\SecurityScheme;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;
use Meilisearch\Meilisearch;
use Spatie\Health\Checks\Checks\EnvironmentCheck;
use Spatie\Health\Checks\Checks\MeilisearchCheck;
use Spatie\Health\Checks\Checks\ScheduleCheck;
use Spatie\Health\Checks\Checks\UsedDiskSpaceCheck;
use Spatie\Health\Facades\Health;
use Spatie\Health\Checks\Checks\DatabaseCheck;
use Spatie\Health\Checks\Checks\RedisCheck;
use Spatie\Health\Checks\Checks\HorizonCheck;
use Spatie\Health\Checks\Checks\OptimizedAppCheck;
use Spatie\Health\Checks\Checks\DebugModeCheck;

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

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

        Gate::define('viewApiDocs', function ($user = null) {
            // Option A : Autoriser tout le monde (Attention : la doc sera publique hors local)
            return true;

            /* // Option B : Autoriser seulement certains emails
            return in_array($user?->email, [
                'admin@tondomaine.com',
            ], true);
            */
        });

        Health::checks([
            DatabaseCheck::new(),
            UsedDiskSpaceCheck::new(),
            RedisCheck::new(),
            ScheduleCheck::new(),
            HorizonCheck::new(),
            OptimizedAppCheck::new(),
            EnvironmentCheck::new(),
            DebugModeCheck::new(),
            MeilisearchCheck::new()
                ->url('http://meilisearch:7700/health')

        ]);
    }
}
