from fastapi import APIRouter, Depends, HTTPException, Body
from sqlalchemy.orm import Session
from starlette import status
from typing import Optional, Dict, Any

from src.apps.base.schemas.response_model import ResponseModel
from src.core.dependencies import get_db
from src.core.exceptions import APIException
from src.utils import constants
from src.utils.guard import get_current_user
from src.apps.wine_match.services import wine_match as wine_match_service
from src.apps.wine_match.schemas.wine_match import WineMatchPayloadSchema

router = APIRouter()

@router.post("/proceed", response_model=ResponseModel, summary="Process wine matching")
async def proceed(
    payload: WineMatchPayloadSchema,
    db: Session = Depends(get_db)
):
    """
    Process wine matching with retailer data (direct conversion from Groovy)
    
    Args:
        payload: Object containing retailers, matchedType, and mode
        db: Database session
    
    Returns:
        ResponseModel: API response with results
    """
    # try:
    # Process the request using the service
    result = await wine_match_service.process_wine_match(db=db, params=payload.model_dump())
    
    # Return successful response
    return ResponseModel(
        data=result,
        status_code=status.HTTP_200_OK,
        success=True,
        message="Wine match job triggered successfully"
    )
    # except Exception as ex:
    #     # Handle other exceptions with a custom API exception
    #     raise APIException(
    #         module="wine match",
    #         status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
    #         error=str(ex)
    #     ) from ex
