"""Revenue Analysis Handler.""" from typing import Annotated from fastapi import APIRouter from fastapi import Query from moneyhub.constants.constants import ONE_MONTH from moneyhub.constants.constants import ORDER_BY_ARTIST_NAME from moneyhub.constants.constants import ORDER_BY_IMPRINT from moneyhub.constants.constants import ORDER_BY_NET_REVENUE_PAYEE_CURRENCY from moneyhub.constants.constants import ORDER_BY_PRODUCT_ID from moneyhub.constants.constants import ORDER_BY_RECORDING_ID from moneyhub.constants.constants import ORDER_BY_SUBACCOUNT_ID from moneyhub.constants.constants import ORDER_BY_TRACK_UNIQUE_ID from moneyhub.constants.constants import OrderBy from moneyhub.constants.constants import OrderDirection from moneyhub.constants.constants import TWO_MONTHS from moneyhub.logic import revenue_analysis as logic from moneyhub.schemas.revenue_analysis import AccountRevenueSchema from moneyhub.schemas.revenue_analysis import AccountStatementPeriodRevenueSchema from moneyhub.schemas.revenue_analysis import PaginatedRevenueByActivityMonthSchema from moneyhub.schemas.revenue_analysis import PaginatedRevenueByArtistSchema from moneyhub.schemas.revenue_analysis import PaginatedRevenueByImprintSchema from moneyhub.schemas.revenue_analysis import PaginatedRevenueByProductSchema from moneyhub.schemas.revenue_analysis import PaginatedRevenueByProjectSchema from moneyhub.schemas.revenue_analysis import PaginatedRevenueByRecordingSchema from moneyhub.schemas.revenue_analysis import PaginatedRevenueByStoreSchema from moneyhub.schemas.revenue_analysis import PaginatedRevenueBySubaccountSchema from moneyhub.schemas.revenue_analysis import PaginatedRevenueByTrackSchema from moneyhub.schemas.revenue_analysis import ResponseRevenueByTransactionTypeSchema from moneyhub.schemas.revenue_analysis import RevenueByCountrySchema from moneyhub.schemas.revenue_analysis import RevenueByProjectRequestSchema from moneyhub.schemas.revenue_analysis import RevenueByStatementPeriodSchema from moneyhub.utils.cache import cache revenue_analysis_router = APIRouter(prefix='/revenue-analysis', tags=['revenue_analysis']) @revenue_analysis_router.get( '/account/{account_id}/product', status_code=200 ) @cache(ttl=TWO_MONTHS) def get_revenue_analysis_by_product( account_id: int, limit: int = 50, offset: int = 0, contract_id: int | None = None, statement_period_id_start: int | None = None, statement_period_id_end: int | None = None, activity_period_id_start: int | None = None, activity_period_id_end: int | None = None, artist_id: int | None = None, subaccount_id: int | None = None, order_by: str | None = ORDER_BY_PRODUCT_ID, order_dir: OrderDirection = OrderDirection.ASC, search_term: str | None = None, store_ids: Annotated[list[int] | None, Query()] = None, country_codes: Annotated[list[str] | None, Query()] = None, transaction_type_ids: Annotated[list[int] | None, Query()] = None, imprint_ids: Annotated[list[int] | None, Query()] = None, is_subaccount: bool = False, project_id: int | None = None ) -> PaginatedRevenueByProductSchema: """GET revenue analysis by product for a specified account. Args: account_id (int): the id of an account limit (int): how many entities to retrieve. offset (int): the offset (for pagination). contract_id (int): the id of a contract to filter by statement_period_id_start (int): Start of the period range statement_period_id_end (int): End of the period range activity_period_id_start (int): Start of the activity period range activity_period_id_end (int): End of the activity period range artist_id (int): the id of an artist to filter by subaccount_id (int): the id of a subaccount to filter by order_by (str): Key to sort by (defaults to no sorting) order_dir (str): Direction to sort by (ASC or DESC) search_term (str): query to search by store_ids (list[int]): list of store IDs to filter by country_codes (list[str]): list of country codes to filter by transaction_type_ids (list[int]): list of transaction type IDs to filter by imprint_ids (list[int]): list of imprint IDs to filter by is_subaccount (bool): whether this is for a subaccount project_id (int): the id of a project to filter by Returns: PaginatedRevenueByProductSchema: list of revenue by product """ return logic.get_revenue_analysis_by_product( account_id, limit, offset, contract_id, statement_period_id_start, statement_period_id_end, activity_period_id_start, activity_period_id_end, artist_id, subaccount_id, order_by, order_dir, search_term, store_ids, country_codes, transaction_type_ids, imprint_ids, is_subaccount, project_id ) @revenue_analysis_router.get( '/account/{account_id}/recording', status_code=200 ) @cache(ttl=TWO_MONTHS) def get_revenue_analysis_by_recording( account_id: int, limit: int = 50, offset: int = 0, contract_id: int | None = None, statement_period_id_start: int | None = None, statement_period_id_end: int | None = None, recording_title: str | None = None, order_by: str | None = ORDER_BY_RECORDING_ID, order_dir: OrderDirection = OrderDirection.ASC, activity_period_id_start: int | None = None, activity_period_id_end: int | None = None, store_ids: Annotated[list[int] | None, Query()] = None, country_codes: Annotated[list[str] | None, Query()] = None, imprint_ids: Annotated[list[int] | None, Query()] = None, transaction_type_ids: Annotated[list[int] | None, Query()] = None, ) -> PaginatedRevenueByRecordingSchema: """GET revenue analysis by recording for a specified account. Args: account_id (int): the id of an account limit (int): how many entities to retrieve. offset (int): the offset (for pagination). contract_id (int): the id of a contract to filter by statement_period_id_start (int): Start of the period range statement_period_id_end (int): End of the period range activity_period_id_start (int): Start of the activity period range activity_period_id_end (int): End of the activity period range recording_title (str): recording name to filter by order_by (str): Key to sort by (defaults to no sorting) order_dir (str): Direction to sort by (ASC or DESC) store_ids (list[int]): list of store IDs to filter by country_codes (list[str]): list of country codes to filter by imprint_ids (list[int]): list of imprint IDs to filter by transaction_type_ids (list[int]): list of transaction type IDs to filter by Returns: list: list of revenue by recording """ return logic.get_revenue_analysis_by_recording( account_id, limit, offset, contract_id, statement_period_id_start, statement_period_id_end, recording_title, order_by, order_dir, activity_period_id_start, activity_period_id_end, store_ids, country_codes, imprint_ids, transaction_type_ids) @revenue_analysis_router.get( '/account/{account_id}/statement-period', status_code=200 ) @cache(ttl=ONE_MONTH) def get_revenue_analysis_by_statement_period( account_id: int, statement_period_id_start: int, statement_period_id_end: int, contract_id: int | None = None, artist_id: int | None = None, product_id: int | None = None, track_unique_id: int | None = None, subaccount_id: int | None = None, is_subaccount: bool = False, activity_period_id_start: int | None = None, activity_period_id_end: int | None = None, store_ids: Annotated[list[int] | None, Query()] = None, country_codes: Annotated[list[str] | None, Query()] = None, imprint_ids: Annotated[list[int] | None, Query()] = None, transaction_type_ids: Annotated[list[int] | None, Query()] = None, project_id: int | None = None, ) -> list[RevenueByStatementPeriodSchema]: """GET revenue analysis by statement period for a specified account. Args: account_id (int): ID of the account contract_id (int): ID of a contract to filter by artist_id (int): ID of an artist to filter by subaccount_id (int): the id of a subaccount to filter by product_id (int): the id of a product to filter by track_unique_id (int): the id of a track to filter by statement_period_id_start (int): Start of the period range statement_period_id_end (int): End of the period range is_subaccount (bool): whether this is for a subaccount activity_period_id_start (int): Start of the activity period range activity_period_id_end (int): End of the activity period range store_ids (list[int]): list of store IDs to filter by country_codes (list[str]): list of country codes to filter by imprint_ids (list[int]): list of imprint IDs to filter by transaction_type_ids (list[int]): list of transaction type IDs to filter by project_id (int | None): the id of a project to filter by Returns: list: list of revenue by statement period """ return logic.get_revenue_analysis_by_statement_period( account_id, contract_id, artist_id, subaccount_id, product_id, track_unique_id, statement_period_id_start, statement_period_id_end, is_subaccount, activity_period_id_start, activity_period_id_end, store_ids, country_codes, imprint_ids, transaction_type_ids, project_id=project_id, ) @revenue_analysis_router.get( '/account/{account_id}/store', status_code=200 ) @cache(ttl=TWO_MONTHS) def get_revenue_analysis_by_store( account_id: int, artist_id: int | None = None, subaccount_id: int | None = None, limit: int = 5, offset: int = 0, contract_id: int | None = None, product_id: int | None = None, track_unique_id: int | None = None, statement_period_id_start: int | None = None, statement_period_id_end: int | None = None, order_by: str = OrderBy.NET_REVENUE_PAYEE_CURRENCY, order_dir: OrderDirection = OrderDirection.DESC, search_term: str | None = None, is_subaccount: bool = False, activity_period_id_start: int | None = None, activity_period_id_end: int | None = None, store_ids: Annotated[list[int] | None, Query()] = None, country_codes: Annotated[list[str] | None, Query()] = None, imprint_ids: Annotated[list[int] | None, Query()] = None, transaction_type_ids: Annotated[list[int] | None, Query()] = None, project_id: int | None = None, ) -> PaginatedRevenueByStoreSchema: """GET revenue analysis by store for a specified account. Args: account_id (int): the id of an account artist_id (int): the id of an artist to filter by subaccount_id (int): the id of a subaccount to filter by limit (int): how many records to retrieve. offset (int): the offset (for pagination). contract_id (int): the id of a contract to filter by product_id (int): the id of a product to filter by track_unique_id (int): the id of a track to filter by statement_period_id_start (int): start of the period range statement_period_id_end (int): end of the period range order_by (str): field to sort by (defaults to net revenue payee currency) order_dir (OrderDirection): direction to sort by (ASC or DESC) search_term (str): query to search by is_subaccount (bool): whether this is for a subaccount activity_period_id_start (int): start of the period range activity_period_id_end (int): end of the period range store_ids (Annotated[list[int] | None, Query()]): stores to filter country_codes (Annotated[list[str] | None, Query()]): countries to filter imprint_ids (Annotated[list[int] | None, Query()]): imprints to filter transaction_type_ids (Annotated[list[int] | None, Query()]): transaction types to filter project_id (int | None): the id of a project to filter by Returns: PaginatedRevenueByStoreSchema: list of revenue by store """ return logic.get_revenue_analysis_by_store( account_id, artist_id, subaccount_id, limit, offset, contract_id, product_id, track_unique_id, statement_period_id_start, statement_period_id_end, order_by, order_dir, search_term, is_subaccount, activity_period_id_start, activity_period_id_end, country_codes, imprint_ids, transaction_type_ids, store_ids, project_id=project_id, ) @revenue_analysis_router.post( '/account/{account_id}/project', status_code=200 ) @cache(ttl=TWO_MONTHS) def get_revenue_analysis_by_project( account_id: int, body: RevenueByProjectRequestSchema, ) -> PaginatedRevenueByProjectSchema: """POST revenue analysis by project for a specified account. Args: account_id (int): the id of an account body (RevenueByProjectRequestSchema): request filters and pagination Returns: PaginatedRevenueByProjectSchema: paginated revenue by project """ return logic.get_revenue_analysis_by_project( account_id, body.limit, body.offset, body.contract_id, body.subaccount_id, body.statement_period_id_start, body.statement_period_id_end, body.order_by, body.order_dir, body.search_term, body.is_subaccount, body.activity_period_id_start, body.activity_period_id_end, body.store_ids, body.country_codes, body.imprint_ids, body.transaction_type_ids, ) @revenue_analysis_router.get( '/account/{account_id}/country', status_code=200 ) @cache(ttl=TWO_MONTHS) def get_revenue_analysis_by_country( account_id: int, artist_id: int | None = None, subaccount_id: int | None = None, product_id: int | None = None, track_unique_id: int | None = None, contract_id: int | None = None, statement_period_id_start: int | None = None, statement_period_id_end: int | None = None, activity_period_id_start: int | None = None, activity_period_id_end: int | None = None, store_ids: Annotated[list[int] | None, Query()] = None, country_codes: Annotated[list[str] | None, Query()] = None, imprint_ids: Annotated[list[int] | None, Query()] = None, transaction_type_ids: Annotated[list[int] | None, Query()] = None, is_subaccount: bool = False, project_id: int | None = None, ) -> list[RevenueByCountrySchema]: """GET revenue analysis by country for a specified account. Args: account_id (int): the id of an account artist_id (int): the id of an artist to filter by subaccount_id (int): the id of a subaccount to filter by product_id (int): the id of a product to filter by track_unique_id (int): the id of a track to filter by contract_id (int): the id of a contract to filter by statement_period_id_start (int): Start of the period range statement_period_id_end (int): End of the period range activity_period_id_start (int): Start of the activity period range activity_period_id_end (int): End of the activity period range store_ids (list[int]): list of store IDs to filter by imprint_ids (list[int]): list of imprint IDs to filter by country_codes (list[str]): list of countries to filter by transaction_type_ids (list[int]): list of transaction type IDs to filter by is_subaccount (bool): Whether the request is made by a subaccount project_id (int | None): the id of a project to filter by Returns: list: list of revenue by country """ return logic.get_revenue_analysis_by_country( account_id, artist_id, subaccount_id, product_id, track_unique_id, contract_id, statement_period_id_start, statement_period_id_end, activity_period_id_start, activity_period_id_end, store_ids, country_codes, imprint_ids, transaction_type_ids, is_subaccount, project_id=project_id, ) @revenue_analysis_router.get( '/account/{account_id}/transaction-type', status_code=200 ) @cache(ttl=TWO_MONTHS) def get_revenue_analysis_by_transaction_type( account_id: int, artist_id: int | None = None, contract_id: int | None = None, statement_period_id_start: int | None = None, statement_period_id_end: int | None = None, activity_period_id_start: int | None = None, activity_period_id_end: int | None = None, subaccount_id: int | None = None, order_by: str = ORDER_BY_NET_REVENUE_PAYEE_CURRENCY, order_dir: OrderDirection = OrderDirection.DESC, search_term: str | None = None, is_subaccount: bool = False, product_id: int | None = None, track_unique_id: int | None = None, store_ids: Annotated[list[int] | None, Query()] = None, country_codes: Annotated[list[str] | None, Query()] = None, imprint_ids: Annotated[list[int] | None, Query()] = None, transaction_type_ids: Annotated[list[int] | None, Query()] = None, project_id: int | None = None, ) -> ResponseRevenueByTransactionTypeSchema: """Get revenue analysis by transaction type for a specified account. Args: account_id (int): ID of the account artist_id (int): the id of an artist to filter by contract_id (int): ID of a contract to filter by statement_period_id_start (int): Start of the period range statement_period_id_end (int): End of the period range activity_period_id_start (int): Start of the activity period range activity_period_id_end (int): End of the activity period range subaccount_id (int): the id of a subaccount to filter by order_by (str): Key to sort by (defaults to sorting by net revenue) order_dir (str): Direction to sort by (defaults to DESC) search_term (str): query to search by is_subaccount (bool): whether this is for a subaccount product_id (int): The id of the product to filter by track_unique_id (int): the ID of the track to filter by store_ids (list[int]): list of store IDs to filter by country_codes (list[str]): list of country codes to filter by imprint_ids (list[int]): list of imprint IDs to filter by transaction_type_ids (list[int]): list of transaction type IDs to filter by project_id (int | None): the id of a project to filter by Returns: ResponseRevenueByTransactionTypeSchema: response schema """ return logic.get_revenue_analysis_by_transaction_type( account_id, artist_id, contract_id, statement_period_id_start, statement_period_id_end, activity_period_id_start, activity_period_id_end, subaccount_id, order_by, order_dir, search_term, is_subaccount, product_id, track_unique_id, store_ids, country_codes, imprint_ids, transaction_type_ids, project_id=project_id, ) @revenue_analysis_router.get( '/account/{account_id}/track', status_code=200 ) @cache(ttl=TWO_MONTHS) def get_revenue_analysis_by_track( account_id: int, limit: int = 50, offset: int = 0, contract_id: int | None = None, statement_period_id_start: int | None = None, statement_period_id_end: int | None = None, activity_period_id_start: int | None = None, activity_period_id_end: int | None = None, artist_id: int | None = None, subaccount_id: int | None = None, product_id: int | None = None, order_by: str | None = ORDER_BY_TRACK_UNIQUE_ID, order_dir: OrderDirection = OrderDirection.ASC, search_term: str | None = None, store_ids: Annotated[list[int] | None, Query()] = None, country_codes: Annotated[list[str] | None, Query()] = None, transaction_type_ids: Annotated[list[int] | None, Query()] = None, imprint_ids: Annotated[list[int] | None, Query()] = None, is_subaccount: bool = False, project_id: int | None = None, ) -> PaginatedRevenueByTrackSchema: """GET revenue analysis by track for a specified account. Args: account_id (int): the id of an account limit (int): how many entities to retrieve. offset (int): the offset (for pagination). contract_id (int): the id of a contract to filter by statement_period_id_start (int): Start of the period range statement_period_id_end (int): End of the period range activity_period_id_start (int): Start of the activity period range activity_period_id_end (int): End of the activity period range artist_id (int): the id of an artist to filter by subaccount_id (int): the id of a subaccount to filter by product_id (int): the id of a product to filter by order_by (str): Key to sort by (defaults to no sorting) order_dir (str): Direction to sort by (ASC or DESC) search_term (str): query to search by store_ids (list[int]): list of store IDs to filter by country_codes (list[str]): list of country codes to filter by transaction_type_ids (list[int]): list of transaction type IDs to filter by imprint_ids (list[int]): list of imprint IDs to filter by is_subaccount (bool): Whether the request is made by a subaccount project_id (int): the id of a project to filter by Returns: PaginatedRevenueByTrackSchema: list of revenue by track """ return logic.get_revenue_analysis_by_track( account_id, limit, offset, contract_id, statement_period_id_start, statement_period_id_end, activity_period_id_start, activity_period_id_end, artist_id, subaccount_id, product_id, order_by, order_dir, search_term, store_ids, country_codes, transaction_type_ids, imprint_ids, is_subaccount, project_id ) @revenue_analysis_router.get( '/account/{account_id}/artist', status_code=200 ) @cache(ttl=TWO_MONTHS) def get_revenue_analysis_by_artist( account_id: int, limit: int = 50, offset: int = 0, contract_id: int | None = None, subaccount_id: int | None = None, statement_period_id_start: int | None = None, statement_period_id_end: int | None = None, activity_period_id_start: int | None = None, activity_period_id_end: int | None = None, order_by: str | None = ORDER_BY_ARTIST_NAME, order_dir: OrderDirection = OrderDirection.ASC, search_term: str | None = None, store_ids: Annotated[list[int] | None, Query()] = None, country_codes: Annotated[list[str] | None, Query()] = None, transaction_type_ids: Annotated[list[int] | None, Query()] = None, imprint_ids: Annotated[list[int] | None, Query()] = None, is_subaccount: bool = False ) -> PaginatedRevenueByArtistSchema: """GET revenue analysis by artist for a specified account. Args: account_id (int): the id of an account limit (int): how many entities to retrieve. offset (int): the offset (for pagination). contract_id (int): the id of a contract to filter by subaccount_id (int): the id of a subaccount to filter by statement_period_id_start (int): Start of the period range statement_period_id_end (int): End of the period range activity_period_id_start (int): Start of the activity period range activity_period_id_end (int): End of the activity period range order_by (str): Key to sort by (defaults to no sorting) order_dir (str): Direction to sort by (ASC or DESC) search_term (str): query to search by store_ids (list[int]): list of store IDs to filter by country_codes (list[str]): list of country codes to filter by transaction_type_ids (list[int]): list of transaction type IDs to filter by imprint_ids (list[int]): list of imprint IDs to filter by is_subaccount (bool): whether this is for a subaccount Returns: PaginatedRevenueByArtistSchema: list of revenue by artist """ return logic.get_revenue_analysis_by_artist( account_id, limit, offset, contract_id, subaccount_id, statement_period_id_start, statement_period_id_end, activity_period_id_start, activity_period_id_end, order_by, order_dir, search_term, store_ids, country_codes, transaction_type_ids, imprint_ids, is_subaccount ) @revenue_analysis_router.get( '/account/{account_id}/subaccount', status_code=200 ) @cache(ttl=TWO_MONTHS) def get_revenue_analysis_by_subaccount( account_id: int, limit: int = 50, offset: int = 0, artist_id: int | None = None, contract_id: int | None = None, store_ids: Annotated[list[int] | None, Query()] = None, activity_period_id_start: int | None = None, activity_period_id_end: int | None = None, imprint_ids: Annotated[list[int] | None, Query()] = None, transaction_type_ids: Annotated[list[int] | None, Query()] = None, country_codes: Annotated[list[str] | None, Query()] = None, statement_period_id_start: int | None = None, statement_period_id_end: int | None = None, order_by: str | None = ORDER_BY_SUBACCOUNT_ID, order_dir: OrderDirection = OrderDirection.ASC, search_term: str | None = None ) -> PaginatedRevenueBySubaccountSchema: """GET revenue analysis by subaccount for a specified account. Args: account_id (int): the id of an account limit (int): how many entities to retrieve. offset (int): the offset (for pagination). artist_id (int): the id of an artist to filter by contract_id (int): the id of a contract to filter by store_ids (list): Optional stores to filter by activity_period_id_start (int): Optional activity period range start activity_period_id_end (int): Optional activity period range end imprint_ids (list): Optional imprints to filter by transaction_type_ids (list): Optional transaction types to filter by country_codes (list): Optional country codes to filter by statement_period_id_start (int): Start of the period range statement_period_id_end (int): End of the period range order_by (str): Key to sort by (defaults to no sorting) order_dir (str): Direction to sort by (ASC or DESC) search_term (str): query to search by Returns: PaginatedRevenueBySubaccountSchema: list of revenue by subaccount """ return logic.get_revenue_analysis_by_subaccount( account_id, limit, offset, artist_id, contract_id, store_ids, activity_period_id_start, activity_period_id_end, imprint_ids, transaction_type_ids, country_codes, statement_period_id_start, statement_period_id_end, order_by, order_dir, search_term ) @revenue_analysis_router.get( '/account/{account_id}/imprint', status_code=200 ) @cache(ttl=TWO_MONTHS) def get_revenue_analysis_by_imprint( account_id: int, artist_id: int | None = None, limit: int = 50, offset: int = 0, contract_id: int | None = None, statement_period_id_start: int | None = None, statement_period_id_end: int | None = None, activity_period_id_start: int | None = None, activity_period_id_end: int | None = None, subaccount_id: int | None = None, order_by: str | None = ORDER_BY_IMPRINT, order_dir: OrderDirection = OrderDirection.ASC, search_term: str | None = None, store_ids: Annotated[list[int] | None, Query()] = None, country_codes: Annotated[list[str] | None, Query()] = None, imprint_ids: Annotated[list[int] | None, Query()] = None, transaction_type_ids: Annotated[list[int] | None, Query()] = None, is_subaccount: bool = False ) -> PaginatedRevenueByImprintSchema: """GET revenue analysis by imprint for a specified account. Args: account_id (int): the id of an account artist_id (int): the id of an artist to filter by limit (int): how many entities to retrieve. offset (int): the offset (for pagination). contract_id (int): the id of a contract to filter by statement_period_id_start (int): Start of the period range statement_period_id_end (int): End of the period range activity_period_id_start (int): Start of the activity period range activity_period_id_end (int): End of the activity period range subaccount_id (int): ID of the subaccount order_by (str): Key to sort by (defaults to no sorting) order_dir (str): Direction to sort by (ASC or DESC) search_term (str | int): query to search by store_ids (list[int]): list of store IDs to filter by country_codes (list[str]): list of country codes to filter by imprint_ids (list[int]): list of imprints to filter by transaction_type_ids (list[int]): list of transaction type IDs to filter by is_subaccount (bool): whether this is for a subaccount Returns: PaginatedRevenueByImprintSchema: list of revenue by imprint """ return logic.get_revenue_analysis_by_imprint( account_id, artist_id, limit, offset, contract_id, statement_period_id_start, statement_period_id_end, activity_period_id_start, activity_period_id_end, subaccount_id, order_by, order_dir, search_term, store_ids, country_codes, imprint_ids, transaction_type_ids, is_subaccount ) @revenue_analysis_router.get( '/account/{account_id}/statement_period/{statement_period}/all-time-revenue', status_code=200 ) @cache(ttl=ONE_MONTH) def get_all_time_revenue_account_id( account_id: int, statement_period: int, is_open_statement_period: bool = True, artist_id: int | None = None, subaccount_id: int | None = None, is_subaccount: bool = False, ) -> AccountRevenueSchema: """GET total revenue for a specified account. Args: account_id (int): The id of an account is_open_statement_period (bool): a boolean flag used by the cache to skip open periods statement_period (int): used by the cache key to identify new statement periods artist_id (int): the id of an artist to filter by subaccount_id (int): the id of a subaccount to filter by is_subaccount (bool): whether this is for a subaccount Returns: dict: dict of revenue information """ return logic.get_revenue_by_account(account_id, artist_id, subaccount_id, is_subaccount) @revenue_analysis_router.get( '/account/{account_id}/statement_period/{statement_period}', status_code=200 ) @cache(ttl=ONE_MONTH) def get_latest_revenue_by_account_statement_period( account_id: int, statement_period: int, artist_id: int | None = None, subaccount_id: int | None = None, product_id: int | None = None, track_unique_id: int | None = None, is_open_statement_period: bool = True, is_subaccount: bool = False, project_id: int | None = None, ) -> AccountStatementPeriodRevenueSchema: """GET latest revenue for a specified account. Args: account_id (int): The id of an account artist_id (int): the id of an artist to filter by subaccount_id (int): the id of a subaccount to filter by product_id (int): the id of a product to filter by track_unique_id (int): the id of a track to filter by is_open_statement_period(bool): a boolean flag used by the cache to skip open periods statement_period (int): latest statement period to filter by is_subaccount (bool): whether this is for a subaccount project_id (int | None): the id of a project to filter by Returns: dict: dict of revenue information """ return logic.get_latest_revenue_by_account_id( account_id, statement_period, artist_id, subaccount_id, product_id, track_unique_id, is_subaccount, project_id ) @revenue_analysis_router.get( '/account/{account_id}/activity-month', status_code=200 ) @cache(ttl=ONE_MONTH) def get_revenue_analysis_by_activity_month( account_id: int, limit: int | None = None, offset: int | None = None, artist_id: int | None = None, subaccount_id: int | None = None, product_id: int | None = None, track_unique_id: int | None = None, contract_id: int | None = None, statement_period_id_start: int | None = None, statement_period_id_end: int | None = None, activity_period_id_start: int | None = None, activity_period_id_end: int | None = None, store_ids: Annotated[list[int] | None, Query()] = None, country_codes: Annotated[list[str] | None, Query()] = None, transaction_type_ids: Annotated[list[int] | None, Query()] = None, imprint_ids: Annotated[list[int] | None, Query()] = None, is_subaccount: bool = False, project_id: int | None = None, ) -> PaginatedRevenueByActivityMonthSchema: """GET revenue analysis by activity month for a specified account. Args: account_id (int): the id of an account limit (int): how many entities to retrieve. offset (int): the offset (for pagination). artist_id (int): the id of an artist to filter by subaccount_id (int): the id of a subaccount to filter by product_id (int): the id of a product to filter by track_unique_id (int): the id of a track to filter by contract_id (int): the id of a contract to filter by statement_period_id_start (int): Start of the period range statement_period_id_end (int): End of the period range activity_period_id_start (int): Start of the activity period range activity_period_id_end (int): End of the activity period range imprint_ids (list[int]): list of imprint IDs to filter by store_ids (list[int]): list of store IDs to filter by country_codes (list[str]): list of country codes to filter by transaction_type_ids (list[int]): list of transaction type IDs to filter by is_subaccount (bool): bool flag to check who is making the request project_id (int | None): the id of a project to filter by Returns: PaginatedRevenueByActivityMonthSchema: list of revenue by activity month """ return logic.get_revenue_analysis_by_activity_month( account_id, limit, offset, artist_id, subaccount_id, product_id, track_unique_id, contract_id, statement_period_id_start, statement_period_id_end, activity_period_id_start, activity_period_id_end, imprint_ids, store_ids, country_codes, transaction_type_ids, is_subaccount, project_id=project_id)