from datetime import datetime
from pydantic import BaseModel, Field, field_validator

class TenantCreate(BaseModel):
    domain: str = Field(..., description="Domain name of the host site (e.g. example.com or localhost:8000)")
    name: str = Field(..., min_length=1, max_length=100, description="Display name for the website/tenant")

    @field_validator("domain")
    @classmethod
    def clean_domain(cls, v: str) -> str:
        domain = v.strip().lower()
        # Strip protocols if user passes full URL
        if domain.startswith("http://"):
            domain = domain[7:]
        elif domain.startswith("https://"):
            domain = domain[8:]
        # Strip trailing slash or path
        domain = domain.split("/")[0]
        if not domain:
            raise ValueError("Domain cannot be empty")
        return domain

class TenantResponse(BaseModel):
    siteId: str
    domain: str
    name: str
    createdAt: datetime
