"""Revenue By Distro Model.""" from sqlalchemy import Column from sqlalchemy import Integer from sqlalchemy.engine import Row from moneyhub.models.snowflake_base import BaseModel class RevenueDistro(BaseModel): """Revenue By Distro model.""" __tablename__ = 'revenue_distro_dbt' account_id = Column(Integer, nullable=False, primary_key=True) subaccount_id = Column(Integer, nullable=True) @classmethod def get_by_account_id( cls, account_id: int, subaccount_id: int | None, is_subaccount: bool ) -> Row: """GET distro revenue for a specified account ID. Args: account_id (int): the id of an account subaccount_id (int): the id of a subaccount to filter by is_subaccount (bool): Whether the request is made by a subaccount Returns: list: list of distro revenue """ filters = [cls.account_id == account_id] if is_subaccount and subaccount_id: filters.append(cls.subaccount_id == subaccount_id) return cls.query.filter(*filters).first()