from datetime import datetime
from pydantic import BaseModel


class SiteCreate(BaseModel):
    name: str
    owner_name: str
    contact_email: str
    license_expires_at: datetime


class SiteUpdate(BaseModel):
    name: str | None = None
    owner_name: str | None = None
    contact_email: str | None = None
    license_expires_at: datetime | None = None


class SiteOut(BaseModel):
    id: int
    site_id: str
    name: str
    owner_name: str
    contact_email: str
    is_active: bool
    is_locked: bool
    lock_reason: str | None
    license_expires_at: datetime
    created_at: datetime
    last_seen_at: datetime | None
    last_seen_ip: str | None

    model_config = {"from_attributes": True}


class SiteCreatedOut(SiteOut):
    secret_key: str


class LockRequest(BaseModel):
    reason: str


class HeartbeatRequest(BaseModel):
    version: str = "1.0.0"
    uptime_seconds: int = 0


class HeartbeatResponse(BaseModel):
    licensed: bool
    locked: bool
    lock_reason: str | None
    expires_at: datetime
