"""ChangeInstances Resource."""

from typing import Any, Dict, List

from netorca_sdk.v2.base import BaseResource
from netorca_sdk.v2.models.change_instance import ChangeInstance


class ChangeInstancesResource(BaseResource):
    """Change Instances resource."""

    endpoint = "change_instances"
    model_class = ChangeInstance

    def get_dependant(self) -> List[Dict[str, Any]]:
        """
        Get dependent change instances.

        Returns:
            List of dependent change instance data
        """
        results = []
        for item in self.client.get(self.endpoint, custom_path="change_instances/dependant"):
            results.append(item)
        return results

    def get_referenced(self, **filters: Any) -> List[Dict[str, Any]]:
        """
        Get referenced change instances.

        Args:
            **filters: Filter parameters

        Returns:
            List of referenced change instance data
        """
        results = []
        for item in self.client.get(self.endpoint, params=filters, custom_path="change_instances/referenced"):
            results.append(item)
        return results

    def get_history(self, change_instance_id: int) -> Dict[str, Any]:
        """
        Get change instance history.

        Args:
            change_instance_id: Change instance ID

        Returns:
            History data
        """
        return self.client.get_one(
            self.endpoint,
            change_instance_id,
            custom_path=f"change_instances/{change_instance_id}/history"
        )
