<?php

declare(strict_types=1);

namespace App\Mail;

use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;

/**
 * Уведомление об автоматически обнаруженном инциденте.
 *
 * Отправляется только для severity=high командой incidents:watch-failures.
 * Subject: [Лидерра HIGH] Incident: {summary first 100}.
 */
final class IncidentDetectedMail extends Mailable
{
    public function __construct(
        public readonly string $summary,
        public readonly string $severity,
    ) {}

    public function envelope(): Envelope
    {
        $subjectSnippet = mb_substr($this->summary, 0, 100);

        return new Envelope(
            subject: "[Лидерра HIGH] Incident: {$subjectSnippet}",
        );
    }

    public function content(): Content
    {
        return new Content(
            text: 'emails.incident_detected_text',
            with: [
                'summary' => $this->summary,
                'severity' => $this->severity,
                'now' => now()->timezone('Europe/Moscow')->toIso8601String(),
            ],
        );
    }
}
