import logging

from celery import shared_task

logger = logging.getLogger(__name__)


@shared_task
def fetch_board_game_expansions(board_game_id, expansions_data):
    from boardgames.models import BoardGame
    from boardgames.utils import fetch_and_link_expansions

    game = BoardGame.objects.filter(id=board_game_id).first()
    if not game:
        logger.warning(
            "Board game not found for expansion linking",
            extra={"board_game_id": board_game_id},
        )
        return

    fetch_and_link_expansions(game, expansions_data)
    logger.info(
        "Linked expansions for board game",
        extra={
            "board_game_id": board_game_id,
            "title": game.title,
            "count": len(expansions_data),
        },
    )
