<?php

declare(strict_types=1);

namespace App\Mail;

use App\Models\Deal;
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;
use Illuminate\Support\Collection;

/**
 * Письмо-сводка о новых сделках за окно (G2-A дайджест).
 * Заменяет пер-лид NewLeadNotification как email-канал события new_lead.
 *
 * @property Collection<int, Deal> $deals
 */
class NewLeadsDigestMail extends Mailable
{
    use Queueable;
    use SerializesModels;

    public function __construct(
        public User $user,
        public Tenant $tenant,
        public Collection $deals,
    ) {}

    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'Лидерра. Новые сделки — '.$this->deals->count(),
        );
    }

    public function content(): Content
    {
        return new Content(
            view: 'emails.new_leads_digest',
            with: [
                'user' => $this->user,
                'tenant' => $this->tenant,
                'deals' => $this->deals,
                'count' => $this->deals->count(),
            ],
        );
    }
}
