from typing import Any from dirty_equals import DirtyEquals from dmp.adapters.meta.models import UserAdAccount from dmp.meta.models import MetaAdAccount class IsUserAdAccount(DirtyEquals[UserAdAccount]): def __init__(self, api_ad_account: UserAdAccount): self.api_ad_account = api_ad_account super().__init__() def equals(self, other: Any) -> bool: if not isinstance(other, MetaAdAccount): return False business_account_id = None business_account_name = None if self.api_ad_account.business: business_account_id = self.api_ad_account.business.id business_account_name = self.api_ad_account.business.name return ( self.api_ad_account.id == other.external_id and self.api_ad_account.name == other.name and business_account_id == other.business_account_id and business_account_name == other.business_account_name and self.api_ad_account.campaigns.summary.total_count == other.campaigns_count ) class IsEmptyUserAdAccount(DirtyEquals[UserAdAccount]): def __init__(self, external_id: str): self.external_id = external_id super().__init__() def equals(self, other: Any) -> bool: if not isinstance(other, MetaAdAccount): return False return ( other.external_id == self.external_id and other.name is None and other.business_account_id is None and other.business_account_name is None and other.business_account_picture_key is None and other.campaigns_count == 0 )