<?php

namespace App\Mail;

use App\Facades\Settings;
use App\Traits\GetsColourSettings;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;

class VehiclesInVideoTokenExpiringMail extends Mailable
{
    use Queueable;
    use SerializesModels;
    use GetsColourSettings;

    public function __construct(private readonly int $daysLeft)
    {
    }

    public function envelope(): Envelope
    {
        $expiryText = $this->daysLeft <= 0
            ? 'has expired'
            : 'expiring in ' . $this->daysLeft . ' day' . ($this->daysLeft !== 1 ? 's' : '');

        return new Envelope(
            subject: 'Vehicles In Video — refresh token ' . $expiryText,
        );
    }

    public function content(): Content
    {
        $expiryText = $this->daysLeft <= 0
            ? 'has expired'
            : 'will expire in ' . $this->daysLeft . ' day' . ($this->daysLeft !== 1 ? 's' : '');

        return new Content(
            view: 'emails.alerts.vehicles-in-video-token-expiring',
            with: [
                'days_left' => $this->daysLeft,
                'expiry_text' => $expiryText,
                'dashboard_url' => config('app.url') . '/settings/vehicles-in-video',
                'site_name' => Settings::get('app-name'),
                'site_logo' => Settings::get('site-logo'),
                'site_logo_alternate' => Settings::get('site-alternate-logo'),
                'colours' => $this->getColourSettings(),
            ],
        );
    }

    public function attachments(): array
    {
        return [];
    }
}
