"""Model for ows-account.""" from http import HTTPStatus from typing import Any from owsrequest import request from video import config from video.constants import service from video.constants.error import ERROR_CODE_INVALID_USAGE, ERROR_MESSAGE_INVALID_USAGE from video.exceptions import InvalidRequest, SubaccountNotFound from video.models.ows.classes.subaccount import Subaccount def get_subaccount(subaccount_id: int) -> dict[str, Any]: """Get a subaccount. Args: subaccount_id (int): subaccount_id of subaccount to get. Returns: dict: The retrieved subaccount. """ product_response = request.process( application=config.SERVICE_NAME, environment=config.ENVIRONMENT, method="GET", service_name=service.OWS_ACCOUNT, path=f"/subaccount/{subaccount_id}", uwsgi_cache_enabled=True, ) if product_response.status_code == HTTPStatus.NOT_FOUND: raise SubaccountNotFound() if not product_response.ok: raise InvalidRequest( ERROR_MESSAGE_INVALID_USAGE, error_code=ERROR_CODE_INVALID_USAGE, ) content = product_response.json() subaccount = ( Subaccount( country_id=content["country_id"], description=content["description"], subaccount_id=content["subaccount_id"], name=content["subaccount_name"], vendor_id=content["vendor_id"], ).to_dict() if content else content ) return subaccount