from pydantic import BaseModel, Field, ConfigDict
from typing import Optional
import uuid
from datetime import datetime, timezone


class LigandCreate(BaseModel):
    name: str
    fano_line: str = ""
    theta_crit: Optional[float] = None
    r_cdr: Optional[float] = None
    sequence: str = ""
    partners: Optional[int] = None
    plddt: Optional[float] = None
    rmsd: Optional[float] = None
    kd_pm: Optional[float] = None
    synthesis_cost: Optional[float] = None
    notes: str = ""


class Ligand(LigandCreate):
    model_config = ConfigDict(extra="ignore")
    id: str = Field(default_factory=lambda: str(uuid.uuid4()))
    created_at: str = Field(default_factory=lambda: datetime.now(timezone.utc).isoformat())


class TargetCreate(BaseModel):
    name: str
    cath_class: str = ""
    fold_type: str = ""
    pdb_id: str = ""
    organism: str = ""
    function: str = ""
    helix_count: Optional[int] = None
    notes: str = ""


class Target(TargetCreate):
    model_config = ConfigDict(extra="ignore")
    id: str = Field(default_factory=lambda: str(uuid.uuid4()))
    created_at: str = Field(default_factory=lambda: datetime.now(timezone.utc).isoformat())


class ExperimentCreate(BaseModel):
    title: str = ""
    ligand_name: str = ""
    target_name: str = ""
    experiment_type: str = ""
    status: str = "planned"
    plddt_result: Optional[float] = None
    rmsd_result: Optional[float] = None
    kd_result: Optional[float] = None
    notes: str = ""
    owner_id: Optional[str] = None


class Experiment(ExperimentCreate):
    model_config = ConfigDict(extra="ignore")
    id: str = Field(default_factory=lambda: str(uuid.uuid4()))
    created_at: str = Field(default_factory=lambda: datetime.now(timezone.utc).isoformat())


class ChatMessage(BaseModel):
    message: str
    session_id: str = "default"


class CalculatorInput(BaseModel):
    r_shape: float
    r_gauge: float
