<?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, событие
 * topup_success).
 *
 * Триггер: после INSERT в balance_transactions с type='topup'. Endpoint
 * пополнения через ЮKassa — отдельный коммит; этот Mailable готов к
 * подключению.
 */
class TopupSuccessNotification extends Mailable
{
    use Queueable;
    use SerializesModels;

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

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

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