<?php

namespace App\Providers;

use App\Notifications\VerifyEmail;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Facades\Gate;

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        // 'App\Models\Model' => 'App\Policies\ModelPolicy',
    ];

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();

        Gate::before(function ($user) {
            return $user->hasRole('super-user') ? true : null;
        });
        Gate::define('super-user', function ($user) {
            return $user->hasRole('super-user') ? true : null;
        });

        VerifyEmail::toMailUsing(function ($notifiable, $url) {
            $emailData = getEmailBody('Verify email address', $url);
            $bodyHtml = $emailData->body;
            return (new MailMessage)
                ->subject($emailData->subject)
                ->view('frontend.email.custom_email', ['body' => $bodyHtml]);
        });
    }
}
