<?php

declare(strict_types=1);

namespace App\Mail;

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

/**
 * Email клиенту Лидерры о приостановке проекта из-за недостаточного баланса.
 *
 * Триггер: RouteSupplierLeadJob::handleInsufficientBalance ловит
 * InsufficientBalanceException, помечает projects.is_active=false и шлёт это
 * письмо с rate-limit 1/час/tenant (Redis SETNX).
 *
 * Spec: docs/superpowers/specs/2026-05-11-plan4-billing-csv-admin-design.md §4.4
 */
final class ZeroBalancePausedMail extends Mailable
{
    use Queueable;
    use SerializesModels;

    public function __construct(
        public readonly Tenant $tenant,
        public readonly Project $project,
        public readonly int $requiredPriceKopecks,
    ) {}

    public function envelope(): Envelope
    {
        return new Envelope(
            subject: "Проект «{$this->project->name}» приостановлен — недостаточно средств",
            to: [$this->tenant->contact_email],
        );
    }

    public function content(): Content
    {
        return new Content(view: 'emails.zero_balance_paused');
    }
}
