"""AI Document model."""

from __future__ import annotations

from typing import Any, Dict, Optional

from netorca_sdk.v2.base import BaseModel


class AIDocument(BaseModel):
    """
    AI Document model.

    Represents a document used for AI processing in NetOrca.

    Attributes:
        id: Document ID
        service: Service reference
        content: Document content
        metadata: Document metadata
        created: Creation timestamp
        modified: Last modification timestamp
    """

    @property
    def service_id(self) -> Optional[int]:
        """Get service ID."""
        service = self.data.get("service")
        if isinstance(service, dict):
            return service.get("id")
        return service

    @property
    def service_name(self) -> Optional[str]:
        """Get service name."""
        service = self.data.get("service")
        if isinstance(service, dict):
            return service.get("name")
        return None

    @property
    def content(self) -> Optional[str]:
        """Get document content."""
        return self.data.get("content")

    @property
    def metadata(self) -> Optional[Dict[str, Any]]:
        """Get document metadata."""
        return self.data.get("metadata")

    @property
    def document_type(self) -> Optional[str]:
        """Get document type."""
        return self.data.get("document_type")

    def __repr__(self) -> str:
        return f"AIDocument(id={self.id}, service_id={self.service_id})"
