<?php

namespace App\Mail;

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

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

    public function __construct(
        private readonly Vehicle $vehicle,
        private readonly string $customerName,
        private readonly ?string $customerEmail,
        private readonly ?string $customerPhone,
        private readonly Carbon $createdAt,
    ) {
    }

    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'Personalised Video Not Found — ' . $this->vehicle->registration_number,
        );
    }

    public function content(): Content
    {
        return new Content(
            view: 'emails.alerts.vehicles-in-video-not-found',
            with: [
                'vehicle_name' => trim(implode(' ', array_filter([
                    $this->vehicle->make?->name ?? null,
                    $this->vehicle->model?->name ?? null,
                    $this->vehicle->derivative,
                ]))),
                'reference' => $this->vehicle->registration_number,
                'customer_name' => $this->customerName,
                'customer_email' => $this->customerEmail,
                'customer_phone' => $this->customerPhone,
                'source' => 'Enquiry',
                'date' => $this->createdAt->format('d/m/Y H:i'),
                '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 [];
    }
}
