"""Spaces Model Classes

Pydantic models for space management operations.
"""

from typing import Optional, List
from pydantic import BaseModel, Field

from .api_model import BasePaginatedResponse, BaseCreateResponse, BaseUpdateResponse, BaseDeleteResponse, BaseOperationResponse


class Space(BaseModel):
    """Space model for VitalGraph database.
    
    Represents a graph space that contains RDF data and knowledge graphs.
    Spaces provide logical separation of data within the VitalGraph system.
    """
    id: Optional[int] = Field(
        None, 
        description="Unique space identifier (auto-generated by server)",
        example=1
    )
    tenant: Optional[str] = Field(
        None, 
        description="Tenant identifier for multi-tenant deployments (optional)",
        example="acme_corp"
    )
    space: str = Field(
        ..., 
        description="Space identifier - unique name for the space (required)",
        example="knowledge_base"
    )
    space_name: str = Field(
        ..., 
        description="Human-readable display name for the space (required)",
        example="Knowledge Base"
    )
    space_description: Optional[str] = Field(
        None, 
        description="Detailed description of the space purpose and contents (optional)",
        example="Primary knowledge base containing product information and documentation"
    )
    update_time: Optional[str] = Field(
        None, 
        description="ISO timestamp of last modification (auto-generated by server)",
        example="2025-01-22T00:36:33.214308"
    )
    
    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "tenant": "acme_corp",
                "space": "knowledge_base",
                "space_name": "Knowledge Base",
                "space_description": "Primary knowledge base containing product information and documentation",
                "update_time": "2025-01-22T00:36:33.214308"
            }
        }


class SpacesListResponse(BasePaginatedResponse):
    """Response model for spaces listing operations."""
    spaces: List[Space] = Field(..., description="List of spaces")


class SpaceCreateResponse(BaseCreateResponse):
    """Response model for space creation operations."""
    space: Optional[Space] = Field(None, description="Created space object")


class SpaceUpdateResponse(BaseUpdateResponse):
    """Response model for space update operations."""
    pass


class SpaceDeleteResponse(BaseDeleteResponse):
    """Response model for space deletion operations."""
    pass


class SpaceOperationResponse(BaseOperationResponse):
    """Response model for general space operations."""
    pass


class SpaceResponse(BaseOperationResponse):
    """Response model for single space retrieval operations."""
    space: Optional[Space] = Field(None, description="Retrieved space (None if not found)")
    
    class Config:
        json_schema_extra = {
            "example": {
                "success": True,
                "message": "Space retrieved successfully",
                "space": {
                    "id": 1,
                    "space": "knowledge_base",
                    "space_name": "Knowledge Base",
                    "space_description": "Primary knowledge base"
                }
            }
        }


class SpaceInfoResponse(BaseOperationResponse):
    """Response model for space info/statistics operations."""
    space: Optional[Space] = Field(None, description="Space information")
    statistics: Optional[dict] = Field(None, description="Space statistics")
    quad_dump: Optional[List[str]] = Field(None, description="Quad logging dump if enabled")