"""Utility Functions For Handlers.""" from artist.constants import headers as headers_constants from artist.models import artist def extract_subaccount_id( *, subaccount_id: int | None, account_type: str | None, account_id: int | None ) -> int | None: """Extract the subaccount id that should be used. Extracts id when given an explicit subaccount id and the account data from Grass. Args: subaccount_id (int | None): explicit subaccount id, if any. account_type (str | None): account type of the authenticated client. account_id (int | None): account id of the authenticated client. Returns: int | None: the extracted subaccount id, or None if not found. """ if account_type != headers_constants.GRASS_ACCOUNT_TYPE_SUBACCOUNT: return subaccount_id return subaccount_id or account_id def extract_vendor_id( *, vendor_id: int | None, account_type: str | None, account_id: int | None ) -> int | None: """Extract the vendor id that should be used. Extracts id when given an explicit vendor id and the account data from Grass. Args: vendor_id (int | None): explicit vendor id, if any. account_type (str | None): account type of the authenticated client. account_id (int | None): account id of the authenticated client. Returns: int | None: the extracted vendor id, or None if not found. """ if account_type != headers_constants.GRASS_ACCOUNT_TYPE_VENDOR: return vendor_id return vendor_id or account_id def check_artist_ownership(artist_id, account_type, account_id): """Check if artist is owned by the given account. Args: artist_id (int): the id of the artist to check account_type (str): type of account (vendor or subaccount) account_id (int): id of the account to check Returns: response.Response: status code 200 if owner, 403 if not owner """ return artist.check_ownership(artist_id, account_type, account_id)