$reasons Razones de la decision (para debugging) * @param int $cacheSeconds Tiempo de cache en segundos */ public function __construct( private bool $showAds, private array $reasons = [], private int $cacheSeconds = self::DEFAULT_CACHE_SECONDS ) { } public function shouldShowAds(): bool { return $this->showAds; } /** * @return array */ public function getReasons(): array { return $this->reasons; } public function getCacheSeconds(): int { return $this->cacheSeconds; } /** * Factory: Crea decision positiva (mostrar ads). */ public static function show(int $cacheSeconds = self::DEFAULT_CACHE_SECONDS): self { return new self( showAds: true, reasons: ['all_conditions_passed'], cacheSeconds: $cacheSeconds ); } /** * Factory: Crea decision negativa (ocultar ads). * * @param array $reasons */ public static function hide(array $reasons, int $cacheSeconds = self::DEFAULT_CACHE_SECONDS): self { return new self( showAds: false, reasons: $reasons, cacheSeconds: $cacheSeconds ); } /** * Serializa a array para respuesta JSON. * * El timestamp se inyecta aqui (no en constructor) para mantener Domain puro. * * @param int $timestamp Unix timestamp actual * @return array{show_ads: bool, reasons: array, cache_seconds: int, timestamp: int} */ public function toArray(int $timestamp): array { return [ 'show_ads' => $this->showAds, 'reasons' => $this->reasons, 'cache_seconds' => $this->cacheSeconds, 'timestamp' => $timestamp, ]; } }