"""Healthcheck Model."""

from typing import Optional

from netorca_sdk.v2.base import BaseModel


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

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

    @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 status(self) -> Optional[str]:
        """Get healthcheck status."""
        return self.data.get('status')

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

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

    @property
    def interval(self) -> Optional[int]:
        """Get check interval in seconds."""
        return self.data.get('interval')

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