<?php
/**
 * User Message Class.
 *
 * Represents messages from the user/human in the conversation.
 *
 * @package   Agenistrator
 * @since     1.0.0
 * @author    Alex Ruban <alex@maximum.guru>
 * @author    Maximum Software Inc <contact@maximum.software>
 * @license   GPL-3.0-only
 * @link      https://agenistrator.com/
 *
 * SPDX-FileCopyrightText: 2025-2026 Alex Ruban <alex@maximum.guru>
 * SPDX-FileCopyrightText: 2025-2026 Maximum Software Inc <contact@maximum.software>
 * SPDX-License-Identifier: GPL-3.0-only
 */

namespace Agenistrator;

// Direct access prevention
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * User_Message class.
 */
class User_Message extends Message {
	/**
	 * Get the message role
	 *
	 * @return string The message role
	 * @since     1.0.0
	 */
	public function get_role() {
		return 'user';
	}

	/**
	 * Create User_Message instance from array data
	 *
	 * @param array $data Message data array
	 * @return User_Message|null Message instance or null if invalid
	 * @since     1.0.0
	 */
	public static function from_array( $data ) {
		// User messages require content
		if ( ! isset( $data['content'] ) || null === $data['content'] ) {
			return null;
		}

		return new self(
			$data['content'],
			$data['metadata'] ?? null,
			$data['timestamp'] ?? time(),
			$data['message_id'] ?? null
		);
	}
}
