<?php

namespace App\Campaigns;

/**
 * Fixed analysis and ingest windows for campaign performance.
 *
 * These values are intentional product defaults — not env-driven.
 */
class PerformanceWindows
{
    /** Re-fetch this many recent hours on each hourly cron run. */
    public const HOURLY_REFRESH_HOURS = 3;

    /** Pull hourly insights in chunks when backfilling campaign lifetime. */
    public const HOURLY_BACKFILL_CHUNK_DAYS = 7;

    /** Do not store hourly rows older than this many days. */
    public const MAX_HISTORY_DAYS = 730;

    /**
     * Hour buckets used later for intraday verdicts (Phase 3+).
     *
     * @return list<int>
     */
    public static function analysisHourLengths(): array
    {
        return [3, 5, 7];
    }

    /**
     * Day buckets used later for campaign verdicts (Phase 3+).
     *
     * @return list<int>
     */
    public static function analysisDayLengths(): array
    {
        return [3, 7];
    }

    public static function maxAnalysisHours(): int
    {
        return max(self::analysisHourLengths());
    }

    /**
     * Fixed analysis windows for verdict evaluation.
     *
     * @return array<string, array{type: string, length: int}>
     */
    public static function analysis(): array
    {
        $windows = [];

        foreach (self::analysisHourLengths() as $hours) {
            $windows[$hours.'h'] = ['type' => 'hours', 'length' => $hours];
        }

        foreach (self::analysisDayLengths() as $days) {
            $windows[$days.'d'] = ['type' => 'days', 'length' => $days];
        }

        return $windows;
    }

    /**
     * @return list<string>
     */
    public static function hourWindowKeys(): array
    {
        return array_map(
            fn (int $hours): string => $hours.'h',
            self::analysisHourLengths(),
        );
    }

    /**
     * @return list<string>
     */
    public static function orderedWindowKeys(): array
    {
        return array_keys(self::analysis());
    }
}
