from sqlalchemy.orm import Session
from models import Agent, SampleAgent
from schemas.agent import AgentCreate
from models import PhoneNumber
from schemas.phone_number import PhoneNumberCreate


def create_agent(db: Session, agent: AgentCreate):
    print(agent,"999090909990909909909090909090090990909099099009909909090")
    db_agent = Agent(
        name=agent.name,
        gender=agent.gender,
        about=agent.about,
        webhook_url=agent.webhook_url,
        voice_id=agent.voice_id,
        language=agent.language,
        response_engine=agent.response_engine,
        voicemail_option=agent.voicemail_option,
        llmCreate= agent.llmCreate,
        company_id= agent.company_id
    )
    db.add(db_agent)
    db.commit()
    db.refresh(db_agent)
    return db_agent


def get_all_sample_agents(db: Session):
    return db.query(SampleAgent).all()


def create_sample_agent(db: Session, agent: AgentCreate):
    db_agent = SampleAgent(
        name=agent.name,
        gender=agent.gender,
        about=agent.about,
        webhook_url=agent.webhook_url,
        voice_id=agent.voice_id,
        language=agent.language,
        response_engine=agent.response_engine,
        voicemail_option=agent.voicemail_option,
        llmCreate= agent.llmCreate
    )
    db.add(db_agent)
    db.commit()
    db.refresh(db_agent)
    return db_agent


def create_phone_number(db: Session, data: dict):
    db_phone = PhoneNumber(
        agent_id= data["agent_id"],
        phone_number=data["phone_number"],
        phone_number_type=data["phone_number_type"],
        phone_number_pretty=data["phone_number_pretty"],
        nickname=data["nickname"],
        inbound_agent_id=data["inbound_agent_id"],
        inbound_agent_version=data["inbound_agent_version"],
        area_code=data["area_code"],
        inbound_webhook_url=data["inbound_webhook_url"],
        last_modification_timestamp=data["last_modification_timestamp"],
        toll_free=data["toll_free"],
        country_code=data["country_code"],
        custom_sms_enabled=data["custom_sms_enabled"],
    )
    db.add(db_phone)
    db.commit()
    db.refresh(db_phone)
    return db_phone