<?php
/**
 * Value object representing an email template payload.
 *
 * @package MailDoctor
 */

namespace MailDoctor\Email;

/**
 * Wraps template metadata and content without changing legacy structure.
 */
class Template {
	/**
	 * Email identifier.
	 */
	private string $email_id;

	/**
	 * Template payload as associative array.
	 *
	 * @var array<string, mixed>
	 */
	private array $data;

	/**
	 * Constructor.
	 *
	 * @param string               $email_id Email identifier.
	 * @param array<string, mixed> $data     Raw template data.
	 */
	public function __construct( string $email_id, array $data ) {
		$this->email_id = $email_id;
		$this->data     = $data;
	}

	public function email_id(): string {
		return $this->email_id;
	}

	/**
	 * Return full template payload (legacy structure).
	 *
	 * @return array<string, mixed>
	 */
	public function to_array(): array {
		return $this->data;
	}

	public function subject(): string {
		return (string) ( $this->data['subject'] ?? '' );
	}

	public function heading(): string {
		return (string) ( $this->data['heading'] ?? '' );
	}

	public function html(): string {
		return (string) ( $this->data['html'] ?? '' );
	}

	public function css(): string {
		return (string) ( $this->data['css'] ?? '' );
	}

	public function source(): string {
		return (string) ( $this->data['source'] ?? '' );
	}

	public function is_active(): bool {
		return (bool) ( $this->data['is_active'] ?? false );
	}
}
