<?php

declare(strict_types=1);

namespace App\Mail;

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

/**
 * Email-уведомление об оплате тарифного счёта (ТЗ §18.5, событие
 * invoice_paid).
 *
 * Триггер: после смены статуса saas_invoice на 'paid'. Endpoint
 * биллинга / webhook ЮKassa — отдельный коммит; этот Mailable готов
 * к подключению.
 */
class InvoicePaidNotification extends Mailable
{
    use Queueable;
    use SerializesModels;

    public function __construct(
        public User $recipient,
        public Tenant $tenant,
        public string $amountRub,
        public ?string $invoiceNumber,
        public ?string $tariffName,
    ) {}

    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'Лидерра. Счёт оплачен',
        );
    }

    public function content(): Content
    {
        return new Content(
            view: 'emails.invoice_paid',
            with: [
                'recipient' => $this->recipient,
                'tenant' => $this->tenant,
                'amountRub' => $this->amountRub,
                'invoiceNumber' => $this->invoiceNumber,
                'tariffName' => $this->tariffName,
            ],
        );
    }
}
