"""Service Model."""

from typing import Any, Dict, List, Optional

from netorca_sdk.v2.base import BaseModel
from netorca_sdk.v2.types import ServiceState


class Service(BaseModel):
    """Service model."""

    @property
    def name(self) -> Optional[str]:
        """Get service name."""
        return self.data.get('name')

    @property
    def title(self) -> Optional[str]:
        """Get service title."""
        return self.data.get('title')

    @property
    def description(self) -> Optional[str]:
        """Get service description."""
        return self.data.get('description')

    @property
    def state(self) -> Optional[str]:
        """Get service state (DRAFT, PUBLISHED, or ARCHIVED)."""
        return self.data.get('state')

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

    @property
    def owner_id(self) -> Optional[int]:
        """Get owner team ID."""
        return self._extract_nested_id(self.data.get('owner'))

    @property
    def owner_name(self) -> Optional[str]:
        """Get owner team name."""
        return self._extract_nested_field(self.data.get('owner'), 'name')

    @property
    def tags(self) -> List[str]:
        """Get service tags."""
        return self.data.get('tags', [])

    @property
    def has_md(self) -> Optional[str]:
        """Check if service has markdown documentation."""
        return self.data.get('has_md')

    @property
    def minimum_version(self) -> Optional[int]:
        """Get minimum version."""
        return self.data.get('minimum_version')

    @property
    def enabled_notifications(self) -> bool:
        """Check if notifications are enabled."""
        return self.data.get('enabled_notifications', False)

    def __repr__(self) -> str:
        """String representation."""
        return f"Service(id={self.id}, name={self.name!r}, state={self.state!r})"
