<?php

namespace App\Mail;

use App\Mail\Concerns\RidesALane;
use App\Mail\Concerns\SendsFromMailbox;
use App\Models\Customer;
use App\Models\MaintenanceWindow;
use App\Services\Mail\MailCatalogue;
use App\Services\Mail\MailPurpose;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Mail\Mailables\Headers;
use Illuminate\Queue\SerializesModels;

class MaintenanceCancelledMail extends Mailable implements ShouldQueue
{
    use Queueable, RidesALane, SendsFromMailbox, SerializesModels;

    /** The ledger row this mail confirms once actually delivered. */
    public ?int $notificationId = null;

    public function __construct(
        public MaintenanceWindow $window,
        public Customer $customer,
    ) {
        $this->mailer(MailCatalogue::mailer('maintenance-cancelled'));
    }

    public function headers(): Headers
    {
        return new Headers(text: $this->notificationId ? ['X-CP-Notification' => (string) $this->notificationId] : []);
    }

    public function envelope(): Envelope
    {
        return $this->mailboxEnvelope(
            MailPurpose::MAINTENANCE,
            __('maintenance.mail_cancel_subject', ['title' => $this->window->title]),
            'maintenance-cancelled',
        );
    }

    public function content(): Content
    {
        return new Content(view: 'mail.maintenance-cancelled', with: [
            'title' => $this->window->title,
            'name' => $this->customer->name,
        ]);
    }
}
