<?php

declare(strict_types=1);

namespace App\Framework\Notification\Templates;

/**
 * Channel-specific Template Customization
 *
 * Allows overriding title/body templates per channel
 * Use case: Telegram supports Markdown, Email supports HTML, SMS is plain text
 */
final readonly class ChannelTemplate
{
    /**
     * @param string|null $titleTemplate Channel-specific title template (null = use default)
     * @param string|null $bodyTemplate Channel-specific body template (null = use default)
     * @param array<string, mixed> $metadata Channel-specific metadata (e.g., parse_mode for Telegram)
     */
    public function __construct(
        public ?string $titleTemplate = null,
        public ?string $bodyTemplate = null,
        public array $metadata = []
    ) {
    }

    public static function create(
        ?string $titleTemplate = null,
        ?string $bodyTemplate = null
    ): self {
        return new self(
            titleTemplate: $titleTemplate,
            bodyTemplate: $bodyTemplate
        );
    }

    public function withMetadata(array $metadata): self
    {
        return new self(
            titleTemplate: $this->titleTemplate,
            bodyTemplate: $this->bodyTemplate,
            metadata: [...$this->metadata, ...$metadata]
        );
    }

    public function hasCustomTitle(): bool
    {
        return $this->titleTemplate !== null;
    }

    public function hasCustomBody(): bool
    {
        return $this->bodyTemplate !== null;
    }
}
