<?php

namespace App\Mail;

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

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

    public function __construct(public Appointment $appointment, Company $company)
    {
        $this->company = $company;
    }

    public function envelope(): Envelope
    {
        return new Envelope(
            subject: "[{$this->company->name}] Programare confirmată — " . $this->appointment->date?->format('d.m.Y'),
            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.appointment-confirmed',
            with: array_merge($this->buildBrandingContext(), [
                'appointment' => $this->appointment,
                'client' => $this->appointment->client,
                'vehicle' => $this->appointment->vehicle,
                'master' => $this->appointment->master,
                'post' => $this->appointment->post,
            ]),
        );
    }
}
