from typing import Optional

from pydantic import BaseModel, field_validator


class Msg(BaseModel):
    msg: str


class Dialog(BaseModel):
    title: str = "INFO:"
    message: str = " Enter dialog message here"
    okButtonText: str = "OK"
    cancelButtonText: str = "Cancel"
    inputType: Optional[str] = None
    defaultText: str = ""


class Notif(BaseModel):
    title: str = "INFO:"
    message: str = " Enter notification message here"
    okButtonText: str = "OK"

    @field_validator("title", "message", "okButtonText", mode="before")
    @classmethod
    def coerce_to_str(cls, v) -> str:
        return str(v)


class DialogResponse(BaseModel):
    inputText: str = ""
    okClicked: bool = False
    cancelClicked: bool = False


class StatusBanner(BaseModel):
    status: Optional[str] = None
    color: Optional[str] = None


class SocketMsg(BaseModel):
    type: str
    toClient: str
    fromClient: str
    data: Optional[dict] = {}

    @field_validator("toClient", "fromClient", mode="before")
    @classmethod
    def coerce_client_id_to_str(cls, v):
        return str(v)

    @field_validator("data", mode="before")
    @classmethod
    def coerce_to_dict(cls, v):
        if not v:
            return {}
        return v
