<?php

namespace App\Mail;

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

class ShopOrderConfirmationMail extends Mailable
{
    use Queueable, SerializesModels;

    public function __construct(
        public OnlineOrder $order,
        public Company $company,
    ) {}

    public function envelope(): Envelope
    {
        $brand = $this->company->display_name ?? $this->company->name;
        return new Envelope(
            subject: "Comanda #{$this->order->number} primită — {$brand}",
        );
    }

    public function content(): Content
    {
        return new Content(
            view: 'emails.shop.order-confirmation',
            with: [
                'order' => $this->order,
                'company' => $this->company,
                'items' => $this->order->items()->get(),
                'trackingUrl' => $this->order->trackingUrl(),
                'currency' => $this->company->settings['currency'] ?? 'MDL',
            ],
        );
    }
}
