from pydantic import BaseModel, Field
from typing import List, Optional
from datetime import datetime
from . import MultiArgsTool

from app.utils.logger import CustomLogger
logger = CustomLogger.get_logger()

# class AgentToolSchema(BaseModel):
#     adult: int = Field(description="tells the number of adults", default=None)
#     child: int = Field(description="tells the number of children", default=None)
#     from_date: datetime = Field(description="Start date of booking", default=None)
#     to_date: datetime = Field(description="End date of booking", default=None)
    

class Details(BaseModel):
    checkinDate:datetime = Field(description="fill checkin date from user query or from conversation history")
    checkoutDate:datetime = Field(description="fill checkout date from user query or from conversation history")
    adultCount: int = Field(description="fill adult count from user query or from conversation history")
    childCount: int = Field(description="fill child count from user query or from conversation history")

class AgentToolSchema(BaseModel):
    answer: str = Field(description="Generate question or answer as a hotel manager")
    followUpResponses:List[str] = Field(description="Generate answers for ur latest answer that you generated now consisting of 2-3 words only. Example '1 adult and 1 child'")
    actionAdult: Optional[bool] = Field(description='if your answer is related to number of adults or children set it  true or otherwise false',default=False)
    actionDate: Optional[bool] = Field(description='if your answer is related to check in and check out dates any set it to true or otherwise false',default=False)
    checkinDate:datetime = Field(description="fill checkin date in the datatype of datetime in python from user query or from conversation history or if date is not found then choode tommorow date" )
    checkoutDate:datetime = Field(description="fill checkout date in the datatype of datetime in python from user query or from conversation history or if date is not found then choode tommorow date")
    adultCount: int = Field(description="Extract adult count from given user query or from previous conversation history")
    childCount: int = Field(description="Extract child count from given user query or from previous conversation history")
    
    def __init__(
            self,
            answer:str = "",
            *,
            followUpResponses:List[str] = [],
            actionAdult:Optional[bool] = False,
            actionDate:Optional[bool] = False,
            checkinDate:datetime = '',
            checkoutDate:datetime = '',
            adultCount:int = 2,
            childCount:int = 0
        ) -> None:
        self.answer = answer
        self.followUpResponses = followUpResponses
        self.actionAdult = actionAdult
        self.actionDate = actionDate
        self.checkinDate = checkinDate
        self.checkoutDate = checkoutDate
        self.adultCount = adultCount
        self.childCount = childCount
    
    def __setattr__(self, name, value) -> None:
        self.__dict__[name] = value
        
    # class Config:
    #     extra = Extra.allow 
    #     arbitrary_types_allowed = True
        
class AgentAnswerTool:
    def __init__(self, question: str) -> None:
        self.question = question
        
    def __call__(self):
        return MultiArgsTool(
            name= "missing_parameters",
            description="Only use this when you have any question for user like number of adults or checkin dates.",
            func= self.find_missing_parameters,
            args_schema= AgentToolSchema,
            return_direct=True
        )
        
    def find_missing_parameters(self, answer, followUpResponses,actionAdult=False,actionDate=False, checkinDate=None, checkoutDate=None, adultCount=0, childCount=0, **kwargs):
        return { 'answer':answer, 'followUpResponses':followUpResponses ,"actionAdult": actionAdult,"actionDate": actionDate,"adultCount":adultCount, "childCount":childCount, "checkinDate":checkinDate,"checkoutDate":checkoutDate}