from typing import Dict, List, Any, Optional
from pydantic import BaseModel, Field
from datetime import datetime


class AlpineBitsHandshakeRequest(BaseModel):
    """Model for AlpineBits handshake request data"""

    action: str = Field(
        ..., description="Action parameter, typically 'OTA_Ping:Handshaking'"
    )
    request_xml: Optional[str] = Field(None, description="XML request document")


class ContactName(BaseModel):
    """Contact name structure"""

    first: Optional[str] = None
    last: Optional[str] = None


class ContactAddress(BaseModel):
    """Contact address structure"""

    street: Optional[str] = None
    city: Optional[str] = None
    state: Optional[str] = None
    country: Optional[str] = None
    postalCode: Optional[str] = None


class Contact(BaseModel):
    """Contact information from Wix form"""

    name: Optional[ContactName] = None
    email: Optional[str] = None
    locale: Optional[str] = None
    company: Optional[str] = None
    birthdate: Optional[str] = None
    labelKeys: Optional[Dict[str, Any]] = None
    contactId: Optional[str] = None
    address: Optional[ContactAddress] = None
    jobTitle: Optional[str] = None
    imageUrl: Optional[str] = None
    updatedDate: Optional[str] = None
    phone: Optional[str] = None
    createdDate: Optional[str] = None


class SubmissionPdf(BaseModel):
    """PDF submission structure"""

    url: Optional[str] = None
    filename: Optional[str] = None


class WixFormSubmission(BaseModel):
    """Model for Wix form submission data"""

    formName: str
    submissions: List[Dict[str, Any]] = Field(default_factory=list)
    submissionTime: str
    formFieldMask: List[str] = Field(default_factory=list)
    submissionId: str
    contactId: str
    submissionsLink: str
    submissionPdf: Optional[SubmissionPdf] = None
    formId: str
    contact: Optional[Contact] = None

    # Dynamic form fields - these will capture all field:* entries
    class Config:
        extra = "allow"  # Allow additional fields not defined in the model
