<?php
/**
 * Cart Recovery — Composition Context DTO
 *
 * Immutable input to the AI composer. Encapsulates everything the
 * composer needs to produce a personalized email so the composer
 * itself stays free of WP/Woo globals and can be unit-tested without
 * a bootstrap.
 *
 * @package Niwa_AI
 * @since   0.12.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

final class Niwa_AI_Cart_Recovery_Composition_Context {

	public const STAGE_MAIL1 = 'mail1';
	public const STAGE_MAIL2 = 'mail2';

	/**
	 * @param string                              $stage              'mail1' | 'mail2'.
	 * @param string                              $locale             WP locale (e.g. 'sr_RS').
	 * @param string                              $customer_name      Known first name or empty.
	 * @param Niwa_AI_Cart_Recovery_Cart_Snapshot $snapshot           Captured cart.
	 * @param string                              $transcript_excerpt Short chat digest (plain text, already truncated).
	 * @param string                              $store_name         Store / brand name for signature.
	 * @param bool                                $has_coupon         Whether the composer should reference a coupon placeholder.
	 * @param int                                 $coupon_ttl_hours   Coupon validity window (for copy like "do kraja dana").
	 */
	public function __construct(
		public readonly string $stage,
		public readonly string $locale,
		public readonly string $customer_name,
		public readonly Niwa_AI_Cart_Recovery_Cart_Snapshot $snapshot,
		public readonly string $transcript_excerpt,
		public readonly string $store_name,
		public readonly bool $has_coupon = false,
		public readonly int $coupon_ttl_hours = 24
	) {}

	public function is_valid(): bool {
		if ( self::STAGE_MAIL1 !== $this->stage && self::STAGE_MAIL2 !== $this->stage ) {
			return false;
		}
		if ( $this->snapshot->is_empty() ) {
			return false;
		}
		return true;
	}
}
