from celery import Celery
from celery.schedules import crontab
from app.config import settings

celery_app = Celery(
    "schaefflerautomat",
    broker=settings.redis_url,
    backend=settings.redis_url,
    include=[
        "app.tasks.step_tasks",
        "app.tasks.ai_tasks",
        "app.tasks.beat_tasks",
        "app.domains.rendering.tasks",
        "app.domains.products.tasks",
        "app.domains.imports.tasks",
        "app.domains.materials.tasks",
    ],
)

celery_app.conf.update(
    task_serializer="json",
    result_serializer="json",
    accept_content=["json"],
    timezone="UTC",
    enable_utc=True,
    task_routes={
        "app.tasks.step_tasks.*": {"queue": "step_processing"},
        "app.tasks.ai_tasks.*": {"queue": "ai_validation"},
        "app.tasks.beat_tasks.*": {"queue": "step_processing"},
        "app.domains.rendering.tasks.*": {"queue": "thumbnail_rendering"},
    },
    beat_schedule={
        "broadcast-queue-status-every-10s": {
            "task": "app.tasks.beat_tasks.broadcast_queue_status",
            "schedule": 10.0,  # every 10 seconds
        },
    },
)
