#!/usr/bin/env python
"""Collect and calculate one real-time revenue forecast."""

from __future__ import annotations

import argparse
import json
import logging

from revenue_forecast_job import run_revenue_forecast_cycle
from run_once import load_environment
from storage import initialize_schema


def parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument(
        "--ignore-runtime-window",
        action="store_true",
        help="Run the read-only forecast outside the configured time window.",
    )
    return parser.parse_args()


def main() -> int:
    load_environment()
    args = parse_args()
    initialize_schema()
    payload = run_revenue_forecast_cycle(
        ignore_runtime_window=args.ignore_runtime_window
    )
    print(json.dumps(payload, ensure_ascii=False))
    return 0


if __name__ == "__main__":
    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s %(levelname)s %(name)s %(message)s",
    )
    raise SystemExit(main())
