<?php

namespace App\Notify;

/**
 * Channel-agnostic message envelope. Channels render this into their own
 * native format (markdown for Slack, MIME for email, plain text for SMS).
 */
class Message
{
    public function __construct(
        public string $event,            // 'critical_alert', 'approval_request', 'kill_switch', ...
        public string $title,            // short headline, e.g. "[CRITICAL] dnsserver.hostseba.com"
        public string $body,             // multi-line plain text body
        public string $severity = 'info',// critical | high | medium | low | info
        public ?string $url = null,      // deep link to the relevant page
        public array $context = [],      // extra structured data — channel-dependent rendering
    ) {}

    /**
     * Markdown-ish rendering — looks reasonable in Telegram MarkdownV2,
     * Slack mrkdwn, Discord plain. Caller can also produce HTML for email.
     */
    public function asPlain(): string
    {
        $sevTag = strtoupper($this->severity);
        $out = "[{$sevTag}] {$this->title}\n\n{$this->body}";
        if ($this->url) $out .= "\n\n→ {$this->url}";
        return $out;
    }

    /**
     * Color hint for channels that support it (Discord embeds, Slack attachments).
     */
    public function color(): string
    {
        return match ($this->severity) {
            'critical' => '#fb7185',
            'high'     => '#ff7849',
            'medium'   => '#fbbf24',
            'low'      => '#7dd3fc',
            default    => '#1cc0d6',
        };
    }
}
