<?php

namespace App\Mail;

use App\Mail\Concerns\UsesTenantBranding;
use App\Models\Central\Company;
use App\Models\Tenant\Vehicle;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;

class ServiceReminderMail extends Mailable
{
    use Queueable, SerializesModels, UsesTenantBranding;

    public function __construct(
        public Vehicle $vehicle,
        public string $reminderType, // 'itp' / 'oil' / 'general'
        public ?string $note,
        Company $company,
    ) {
        $this->company = $company;
    }

    public function envelope(): Envelope
    {
        $titles = ['itp' => 'Reminder ITP', 'oil' => 'Reminder schimb ulei', 'general' => 'Reminder revizie'];
        $title = $titles[$this->reminderType] ?? 'Reminder';

        return new Envelope(
            subject: "[{$this->company->name}] {$title} — " . trim(($this->vehicle->make ?? '') . ' ' . ($this->vehicle->model ?? '')),
            from: new \Illuminate\Mail\Mailables\Address(
                config('mail.from.address'),
                $this->company->display_name ?? $this->company->name,
            ),
        );
    }

    public function content(): Content
    {
        return new Content(
            view: 'emails.service-reminder',
            with: array_merge($this->buildBrandingContext(), [
                'vehicle' => $this->vehicle,
                'client' => $this->vehicle->client,
                'reminderType' => $this->reminderType,
                'note' => $this->note,
            ]),
        );
    }
}
