"""Celery tasks for Azure AI validation."""
import logging
from app.tasks.celery_app import celery_app

logger = logging.getLogger(__name__)


@celery_app.task(bind=True, name="app.tasks.ai_tasks.validate_item", queue="ai_validation")
def validate_item(self, order_item_id: str):
    """Validate orientation of a rendered thumbnail via Azure GPT-4o Vision."""
    logger.info(f"AI validation for item: {order_item_id}")
    try:
        from app.services.azure_ai import validate_thumbnail
        validate_thumbnail(order_item_id)
    except Exception as exc:
        logger.error(f"AI validation failed for {order_item_id}: {exc}")
        raise self.retry(exc=exc, countdown=30, max_retries=3)
