from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from app.database.database import get_db
from app.models import ContactMessage
from app.schemas.contact import ContactMessageCreate, ContactMessageResponse

router = APIRouter(prefix="/api/contact", tags=["contact"])


@router.post("", response_model=ContactMessageResponse)
def send_contact_message(message: ContactMessageCreate, db: Session = Depends(get_db)):
    message_data = message.model_dump() if hasattr(message, 'model_dump') else message.dict()
    db_message = ContactMessage(**message_data)
    db.add(db_message)
    db.commit()
    db.refresh(db_message)
    return db_message
