"""ChangeInstance Model."""

from typing import Optional

from netorca_sdk.v2.base import BaseModel


class ChangeInstance(BaseModel):
    """Change Instance model."""

    @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 service_id(self) -> Optional[int]:
        """Get associated service ID."""
        return self._extract_nested_id(self.data.get('service'))

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

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

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

    @property
    def deployed_item_id(self) -> Optional[int]:
        """Get deployed item ID."""
        return self._extract_nested_id(self.data.get('deployed_item'))

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