"""Model for ows-artist.""" from http import HTTPStatus from typing import Any from owsrequest import request from video import config from video.constants import service from video.exceptions import ArtistNotFound, ArtistOwnershipError from video.models.ows.classes.artist import Artist def get_artist(artist_id: int) -> dict[str, Any]: """Get artist. Args: artist_id (int): artist id. Returns: dict[str, Any]: The retrieved artist. """ artist_response = request.process( application=config.SERVICE_NAME, environment=config.ENVIRONMENT, method="GET", service_name=service.OWS_ARTIST, path=f"/artist/{artist_id}", uwsgi_cache_enabled=True, headers={"Content-Type": "application/json"}, ) if artist_response.status_code == HTTPStatus.NOT_FOUND: raise ArtistNotFound() artist_response.raise_for_status() return Artist(artist_response.json()).to_dict() def check_artist_ownership( artist_id: int, account_type: str | None = None, account_id: str | None = None ) -> None: """Check artist ownership. Args: artist_id (int): artist id. account_type (str): Grass account type. account_id (str): Grass account id. Raises: ArtistOwnershipError: if the upstream service denies access. """ if not account_type and not account_id: return request_url = f"/{account_type}/{account_id}/artist/{artist_id}" ownership_response = request.process( application=config.SERVICE_NAME, environment=config.ENVIRONMENT, method="GET", service_name=service.OWS_ARTIST, uwsgi_cache_enabled=True, path=request_url, ) if not ownership_response.ok: raise ArtistOwnershipError()