<?php

namespace App\Notifications;

use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Config;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Bus\Queueable;

class CustomVerifyEmail extends VerifyEmail implements ShouldQueue
{
    use Queueable;
    
    protected function verificationUrl($notifiable)
    {
        
        if (static::$createUrlCallback) {
            return call_user_func(static::$createUrlCallback, $notifiable);
        }

        // Temporarily force the root URL to a.com
        // $originalDomain = config('app.url');
        // URL::forceRootUrl('https://ge-as.support'); // Override

        // Generate the signed URL 
        $url = URL::temporarySignedRoute(
            'verification.verify',
            Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)),
            [
                'id' => $notifiable->getKey(),
                'hash' => sha1($notifiable->getEmailForVerification()),
            ]
        );

        // Restore the original domain 
        // URL::forceRootUrl($originalDomain);

        return $url;
    }
    
    
    public function toMail($notifiable)
    {
        $verificationUrl = $this->verificationUrl($notifiable);
    
        return (new \Illuminate\Notifications\Messages\MailMessage)
            ->subject('Action required - Email Verification')
            ->line("Welcome onboard!") // Include username
            ->line('To continue setting up your store on GEAS, click the button below to verify your email address.')
            ->action('Verify My Email', $verificationUrl)
            ->line('If you have any questions or need assistance, feel free to reach out to our support team at c2cstore@ge-as.support');
            
            
        // return (new \Illuminate\Notifications\Messages\MailMessage)
        //     ->subject('Action required - Email Verification')
        //     ->view(
        //         'emails.onboarding', [
        //             'action' => [
        //                 'Verify email',
        //                 $verificationUrl,
        //             ],
        //             'preActionLines' => [
        //                 'Hello,',
        //                 'Welcome onboard to GEAS,',
        //                 'to continue setting up your store on GEAS, click the button below to verify your email address.',
        //             ],
        //             'postActionLines' => [
        //                 'If you have any questions or need assistance, feel free to reach out to our support team at c2cstore@ge-as.support',
        //             ]
        //         ]
        //     );
    }
}