"""
Pydantic schemas for Client model.

Request and response schemas for client organizations.
"""

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

from pydantic import BaseModel, Field


class ClientBase(BaseModel):
    """Base schema with shared Client fields."""

    name: str = Field(..., description="Client name (unique)")
    type: str = Field(..., description="Client type: msp_client, internal, project")
    network_subnet: Optional[str] = Field(None, description="Client network subnet (e.g., '192.168.0.0/24')")
    domain_name: Optional[str] = Field(None, description="Active Directory domain or primary domain")
    m365_tenant_id: Optional[str] = Field(None, description="Microsoft 365 tenant ID (UUID format)")
    primary_contact: Optional[str] = Field(None, description="Primary contact person")
    notes: Optional[str] = Field(None, description="Additional notes about the client")
    is_active: bool = Field(True, description="Whether client is currently active")


class ClientCreate(ClientBase):
    """Schema for creating a new Client."""
    pass


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

    name: Optional[str] = Field(None, description="Client name (unique)")
    type: Optional[str] = Field(None, description="Client type: msp_client, internal, project")
    network_subnet: Optional[str] = Field(None, description="Client network subnet (e.g., '192.168.0.0/24')")
    domain_name: Optional[str] = Field(None, description="Active Directory domain or primary domain")
    m365_tenant_id: Optional[str] = Field(None, description="Microsoft 365 tenant ID (UUID format)")
    primary_contact: Optional[str] = Field(None, description="Primary contact person")
    notes: Optional[str] = Field(None, description="Additional notes about the client")
    is_active: Optional[bool] = Field(None, description="Whether client is currently active")


class ClientResponse(ClientBase):
    """Schema for Client responses with ID and timestamps."""

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

    model_config = {"from_attributes": True}
