<?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, событие low_balance).
 *
 * Триггер: tenant.balance_leads <= system_settings.low_balance_threshold_leads
 * (default 10) после lead_charge в ProcessWebhookJob.
 */
class LowBalanceNotification extends Mailable
{
    use Queueable;
    use SerializesModels;

    public function __construct(
        public User $recipient,
        public Tenant $tenant,
        public int $thresholdLeads,
    ) {}

    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'Лидерра. Низкий баланс — пополните, чтобы не пропустить лиды',
        );
    }

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