from typing import Literal, Optional

from pydantic import BaseModel, Field


class WhatsAppSettingsResponse(BaseModel):
    whatsapp_enabled: bool = False
    whatsapp_api_provider: str = "whatsapp_business"
    whatsapp_business_token_set: bool = False
    whatsapp_business_phone_id: str = ""
    twilio_account_sid_set: bool = False
    twilio_auth_token_set: bool = False
    twilio_whatsapp_number: str = ""
    configured: bool = False


class WhatsAppSettingsUpdate(BaseModel):
    whatsapp_enabled: Optional[bool] = None
    whatsapp_api_provider: Optional[Literal["whatsapp_business", "twilio"]] = None
    whatsapp_business_token: Optional[str] = None
    whatsapp_business_phone_id: Optional[str] = None
    twilio_account_sid: Optional[str] = None
    twilio_auth_token: Optional[str] = None
    twilio_whatsapp_number: Optional[str] = None


class WhatsAppTestResponse(BaseModel):
    success: bool
    message: str
    provider: Optional[str] = None
    display_phone_number: Optional[str] = None


class SendLoginWhatsAppRequest(BaseModel):
    phone_number: Optional[str] = Field(None, description="E.164 or local; required if user has no phone")
    user_id: Optional[str] = Field(None, description="Target user; omit for self (cloud login card)")
    include_password: bool = False
    prefer_cloud: bool = Field(False, description="LAN admin: send cloud hub URL + codes")
    custom_message: Optional[str] = Field(None, max_length=500)
    temporary_password: Optional[str] = Field(
        None,
        description="Plain password to include (e.g. just-generated temp password)",
    )


class SendLoginWhatsAppResponse(BaseModel):
    success: bool
    message: str
    phone_number: Optional[str] = None
    preview: Optional[str] = None
