from pydantic import BaseModel
from typing import Optional, List
from datetime import datetime


class InquiryCreate(BaseModel):
    category: str = "general"
    subject: Optional[str] = None
    message: str
    contact_email: Optional[str] = None
    contact_phone: Optional[str] = None
    car_id: Optional[int] = None  # For backward compatibility


class InquiryResponse(BaseModel):
    id: int
    user_id: Optional[int] = None
    car_id: Optional[int] = None
    category: Optional[str] = "general"
    subject: Optional[str] = None
    message: str
    contact_email: Optional[str] = None
    contact_phone: Optional[str] = None
    status: str
    admin_response: Optional[str] = None
    responded_at: Optional[datetime] = None
    responded_by: Optional[int] = None
    created_at: datetime
    updated_at: Optional[datetime] = None

    class Config:
        from_attributes = True


class InquiryMessageCreate(BaseModel):
    message: str


class InquiryMessageResponse(BaseModel):
    id: int
    inquiry_id: int
    user_id: int
    message: str
    is_admin: bool
    created_at: datetime

    class Config:
        from_attributes = True


class InquiryWithMessages(BaseModel):
    inquiry: InquiryResponse
    messages: List[InquiryMessageResponse]


class InquiryListResponse(BaseModel):
    inquiries: List[InquiryResponse]
    total: int


class AdminInquiryRespond(BaseModel):
    message: str
    status: Optional[str] = None  # Can update status with response


class AdminInquiryUpdateStatus(BaseModel):
    status: str
