"""ARQ worker entry point.

Run with: python -m arq workers.main.WorkerSettings
"""
import os

from arq.connections import RedisSettings
from arq.cron import cron

# Import all SQL models so SQLAlchemy can resolve FK references
from models.sql.user import UserModel  # noqa: F401
from models.sql.client import ClientModel  # noqa: F401
from models.sql.team import TeamModel  # noqa: F401
from models.sql.presentation import PresentationModel  # noqa: F401

from workers.master_deck_worker import parse_master_deck_task
from workers.presentation_worker import generate_presentation_task
from workers.retention_worker import retention_cleanup_task, retention_purge_task


def _get_redis_settings() -> RedisSettings:
    url = os.environ.get("REDIS_URL", "redis://localhost:6379/0")
    return RedisSettings.from_dsn(url)


class WorkerSettings:
    redis_settings = _get_redis_settings()
    functions = [generate_presentation_task, parse_master_deck_task]
    cron_jobs = [
        cron(retention_cleanup_task, hour=2, minute=0),          # Daily at 2:00 AM
        cron(retention_purge_task, weekday=0, hour=3, minute=0), # Weekly Monday 3:00 AM
    ]
    max_jobs = 5
    job_timeout = 5400  # 90 minutes (master deck with 20+ layouts = ~44 LLM calls)
    max_tries = 3
    health_check_interval = 30
