from fastapi import APIRouter, Depends, Query, status
from sqlalchemy.orm import Session
from uuid import UUID

from src.apps.base.schemas.response_model import ResponseModel
from src.utils import constants
from src.core.dependencies import get_db
from src.utils.constants import MAX_PER_PAGE
from typing import Optional
from src.apps.wine.external_input.service.external_input import check_addition_matched,undo_match,accept_match
from src.apps.wine.external_input.schemas.external_input import AdditionMatchCheckSchema,UndoMatchSchema,AcceptMatchSchema

router = APIRouter(prefix="", tags=["External Inputs"])

@router.get("/check-addition-matched", response_model=ResponseModel, summary="Check if a wine addition has already been matched")
async def check_addition_match(
    payload: AdditionMatchCheckSchema = Depends(),
    db: Session = Depends(get_db),
):
    """
    Check if a wine with the given mongo_id already exists in the database.
    """
    data = await check_addition_matched(db, payload)
    return ResponseModel(
        data=data,
        status_code=status.HTTP_200_OK,
        success=True,
        message="Check addition matched successfully"
    )
    
@router.put("/accept-match", response_model=ResponseModel, summary="Accept the match for a given wine by its ID")
async def accept_wine_match(
    payload: AcceptMatchSchema,
    db: Session = Depends(get_db),
):
    """
    Accept the match for a given wine by its ID.
    This involves updating the wine details based on the provided information.
    """
    data = await accept_match(db, payload)
    return ResponseModel(
        data=data,
        status_code=status.HTTP_200_OK,
        success=True,
        message="Accept match successfully"
    )
    
@router.put("/undo-match", response_model=ResponseModel, summary="Undo the match for a given wine by its ID")
async def undo_wine_match(
    payload: UndoMatchSchema,
    db: Session = Depends(get_db),
):
    """
    Undo the match for a given wine by its ID.
    This involves deleting associated retailer wines, wine duplications, and the wine itself.
    """
    data = await undo_match(db, payload)
    return ResponseModel(
        data=data,
        status_code=status.HTTP_200_OK,
        success=True,
        message="Undo match successfully"
    )