"""
Pydantic schemas for Network model.

Request and response schemas for network segments and VLANs.
"""

from datetime import datetime
from typing import Optional
from uuid import UUID

from pydantic import BaseModel, Field


class NetworkBase(BaseModel):
    """Base schema with shared Network fields."""

    client_id: Optional[UUID] = Field(None, description="Reference to the client")
    site_id: Optional[UUID] = Field(None, description="Reference to the site")
    network_name: str = Field(..., description="Name of the network")
    network_type: Optional[str] = Field(None, description="Type: lan, vpn, vlan, isolated, dmz")
    cidr: str = Field(..., description="Network CIDR notation (e.g., '192.168.0.0/24')")
    gateway_ip: Optional[str] = Field(None, description="Gateway IP address")
    vlan_id: Optional[int] = Field(None, description="VLAN ID if applicable")
    notes: Optional[str] = Field(None, description="Additional notes")


class NetworkCreate(NetworkBase):
    """Schema for creating a new Network."""
    pass


class NetworkUpdate(BaseModel):
    """Schema for updating an existing Network. All fields are optional."""

    client_id: Optional[UUID] = Field(None, description="Reference to the client")
    site_id: Optional[UUID] = Field(None, description="Reference to the site")
    network_name: Optional[str] = Field(None, description="Name of the network")
    network_type: Optional[str] = Field(None, description="Type: lan, vpn, vlan, isolated, dmz")
    cidr: Optional[str] = Field(None, description="Network CIDR notation (e.g., '192.168.0.0/24')")
    gateway_ip: Optional[str] = Field(None, description="Gateway IP address")
    vlan_id: Optional[int] = Field(None, description="VLAN ID if applicable")
    notes: Optional[str] = Field(None, description="Additional notes")


class NetworkResponse(NetworkBase):
    """Schema for Network responses with ID and timestamps."""

    id: UUID = Field(..., description="Unique identifier for the network")
    created_at: datetime = Field(..., description="Timestamp when the network was created")
    updated_at: datetime = Field(..., description="Timestamp when the network was last updated")

    model_config = {"from_attributes": True}
