"""DeployedItem Model."""

from typing import Optional

from netorca_sdk.v2.base import BaseModel


class DeployedItem(BaseModel):
    """Deployed Item model."""

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

    @property
    def service_item_id(self) -> Optional[int]:
        """Get associated service item ID."""
        return self._extract_nested_id(self.data.get('service_item'))

    @property
    def change_instance_id(self) -> Optional[int]:
        """Get associated change instance ID."""
        return self._extract_nested_id(self.data.get('change_instance'))

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

    @property
    def data_field(self) -> Optional[dict]:
        """Get deployed item data."""
        return self.data.get('data')

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