"""Recreate the synthetic guide fixtures. No camera data or model output is used."""

import json
import math
import random
from datetime import datetime, timedelta, timezone
from pathlib import Path
from zoneinfo import ZoneInfo


def main():
    directory = Path(__file__).resolve().parent
    madrid = ZoneInfo("Europe/Madrid")
    start = datetime(2026, 8, 21, tzinfo=madrid).astimezone(timezone.utc)
    random_source = random.Random(26)
    observations = []
    opening = []
    for index in range(56 * 24 + 24):
        instant = start + timedelta(hours=index)
        local = instant.astimezone(madrid)
        is_open = int(local.weekday() != 0 and 12 <= local.hour < 24)
        opening.append(is_open)
        if index >= 56 * 24:
            continue
        lunch = 27 * math.exp(-((local.hour - 14) / 1.35) ** 2)
        dinner = 34 * math.exp(-((local.hour - 21) / 1.5) ** 2)
        weekend = 1.35 if local.weekday() >= 4 else 1.0
        count = max(0, round((3 + lunch + dinner) * weekend + random_source.gauss(0, 2))) if is_open else 0
        observations.append({
            "timestamp_utc": instant.isoformat(),
            "timestamp_local": local.isoformat(),
            "entries": count,
            "is_open": is_open,
            "coverage": 1.0,
        })
    history = {
        "synthetic": True,
        "source": "Deterministic teaching fixture; not camera observations or YOLO output.",
        "timezone": "Europe/Madrid",
        "interval_seconds": 3600,
        "observations": observations,
    }
    request = {
        "horizon": 24,
        "return_quantiles": True,
        "use_symmetric_averaging": False,
        "inputs": [{
            "id": "restaurante-demo-entradas",
            "target": [[row["entries"] for row in observations]],
            "past_future_covariates": [opening],
        }],
    }
    for filename, value in [("history.json", history), ("forecast-draft.json", request)]:
        (directory / filename).write_text(json.dumps(value, ensure_ascii=False, indent=2) + "\n")
    print(f"Created {len(observations)} hourly observations and a {request['horizon']}-step request.")


if __name__ == "__main__":
    main()
