"""preferred response class for all API requests"""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/client/99_DomoEntity.ipynb.

# %% auto 0
__all__ = ['DomoEntity', 'DomoEntity_w_Lineage', 'DomoSubEntity']

# %% ../../nbs/client/99_DomoEntity.ipynb 2
import domolibrary.client.DomoAuth as dmda

import abc
from dataclasses import dataclass, field

from typing import Any



# %% ../../nbs/client/99_DomoEntity.ipynb 4
@dataclass
class DomoEntity(abc.ABC):
    auth: dmda.DomoAuth = field(repr=False)

    id: str

    def __eq__(self, other):
        if isinstance(other, DomoEntity):
            return self.id == other.id
        
        return False
    

    @classmethod
    @abc.abstractmethod
    async def get_by_id(cls, auth: dmda.DomoAuth, entity_id: str):
        """
        Fetches an entity by its ID.
        """
        raise NotImplementedError("This method should be implemented by subclasses.")
    
    @abc.abstractmethod
    def display_url(self) -> str:
        """
        Returns the URL to display the entity in Domo.
        """
        raise NotImplementedError("This method should be implemented by subclasses.")


@dataclass
class DomoEntity_w_Lineage(DomoEntity, abc.ABC):

    Lineage: Any = field(repr=False)

    def __post_init__(self):
        
        import domolibrary.classes.DomoLineage as dmdl
        
        self.Lineage = dmdl.DomoLineage.from_parent(auth = self.auth, 
                                                         parent = self)

    @classmethod
    @abc.abstractmethod
    async def _get_entity_by_id(cls, auth: dmda.DomoAuth, entity_id: str):
        """
        Fetches an entity by its ID.
        This method should be implemented by subclasses to fetch the specific entity type.
        """
        raise NotImplementedError("This method should be implemented by subclasses.")

# %% ../../nbs/client/99_DomoEntity.ipynb 5
@dataclass
class DomoSubEntity(abc.ABC):
    auth: dmda.DomoAuth = field(repr=False)
    parent : Any
    parent_id : str

    def __post_init__(self):
        if self.parent: 
            self.auth = self.parent.auth
            self.parent_id = self.parent.id

    @classmethod
    @abc.abstractmethod
    def _from_parent(cls, parent: DomoEntity):
        cls(
            auth = parent.auth,
            parent = parent,
            parent_id = parent.id
        )
        
        
