<?php

namespace App\Providers;

use Carbon\Carbon;
use Dedoc\Scramble\Scramble;
use Dedoc\Scramble\Support\Generator\OpenApi;
use Dedoc\Scramble\Support\Generator\SecurityScheme;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;

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

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        Carbon::setLocale('id');
        setlocale(LC_TIME, 'id_ID.UTF-8');

        Scramble::configure()
        ->withDocumentTransformers(function (OpenApi $openApi) {
            $openApi->secure(
                SecurityScheme::http('bearer')
            );
        });

        Gate::define('viewPulse', function ($user = null) {
            $monitoringUser = request()->user('monitoring');
            return $monitoringUser && $monitoringUser->email === 'superadminMonitoring@humicengineering.com';
        });

        Gate::define('viewApiDocs', function ($user = null) {
            $monitoringUser = request()->user('monitoring');
            return $monitoringUser && $monitoringUser->email === 'superadminMonitoring@humicengineering.com';
        });
    }
}
