from http import HTTPStatus from typing import Any, Dict, List, Optional, Union, cast import httpx from ... import errors from ...client import AuthenticatedClient, Client from ...models.campaign_objective import CampaignObjective from ...models.campaign_platform import CampaignPlatform from ...models.campaign_status import CampaignStatus from ...models.http_validation_error import HTTPValidationError from ...models.limit_offset_page_meta_campaign import LimitOffsetPageMetaCampaign from ...types import UNSET, Response, Unset def _get_kwargs( *, client: AuthenticatedClient, vendor_id: Union[Unset, None, int] = UNSET, subaccount_id: Union[Unset, None, int] = UNSET, global_participant_ids: Union[Unset, None, List[str]] = UNSET, statuses: Union[Unset, None, List[CampaignStatus]] = UNSET, objectives: Union[Unset, None, List[CampaignObjective]] = UNSET, platforms: Union[Unset, None, List[CampaignPlatform]] = UNSET, search: Union[Unset, None, str] = UNSET, order_by: Union[Unset, None, str] = "createdAt.desc", limit: Union[Unset, None, int] = 50, offset: Union[Unset, None, int] = 0, ) -> Dict[str, Any]: url = "{}/meta/campaigns".format(client.base_url) headers: Dict[str, str] = client.get_headers() cookies: Dict[str, Any] = client.get_cookies() params: Dict[str, Any] = {} params["vendorId"] = vendor_id params["subaccountId"] = subaccount_id json_global_participant_ids: Union[Unset, None, List[str]] = UNSET if not isinstance(global_participant_ids, Unset): if global_participant_ids is None: json_global_participant_ids = None else: json_global_participant_ids = global_participant_ids params["globalParticipantIds"] = json_global_participant_ids json_statuses: Union[Unset, None, List[str]] = UNSET if not isinstance(statuses, Unset): if statuses is None: json_statuses = None else: json_statuses = [] for statuses_item_data in statuses: statuses_item = statuses_item_data.value json_statuses.append(statuses_item) params["statuses"] = json_statuses json_objectives: Union[Unset, None, List[str]] = UNSET if not isinstance(objectives, Unset): if objectives is None: json_objectives = None else: json_objectives = [] for objectives_item_data in objectives: objectives_item = objectives_item_data.value json_objectives.append(objectives_item) params["objectives"] = json_objectives json_platforms: Union[Unset, None, List[str]] = UNSET if not isinstance(platforms, Unset): if platforms is None: json_platforms = None else: json_platforms = [] for platforms_item_data in platforms: platforms_item = platforms_item_data.value json_platforms.append(platforms_item) params["platforms"] = json_platforms params["search"] = search params["orderBy"] = order_by params["limit"] = limit params["offset"] = offset params = {k: v for k, v in params.items() if v is not UNSET and v is not None} return { "method": "get", "url": url, "headers": headers, "cookies": cookies, "timeout": client.get_timeout(), "follow_redirects": client.follow_redirects, "params": params, } def _parse_response( *, client: Client, response: httpx.Response ) -> Optional[Union[HTTPValidationError, LimitOffsetPageMetaCampaign]]: if response.status_code == HTTPStatus.OK: response_200 = LimitOffsetPageMetaCampaign.from_dict(response.json()) return response_200 if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) return response_422 if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None def _build_response( *, client: Client, response: httpx.Response ) -> Response[Union[HTTPValidationError, LimitOffsetPageMetaCampaign]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=_parse_response(client=client, response=response), ) def sync_detailed( *, client: AuthenticatedClient, vendor_id: Union[Unset, None, int] = UNSET, subaccount_id: Union[Unset, None, int] = UNSET, global_participant_ids: Union[Unset, None, List[str]] = UNSET, statuses: Union[Unset, None, List[CampaignStatus]] = UNSET, objectives: Union[Unset, None, List[CampaignObjective]] = UNSET, platforms: Union[Unset, None, List[CampaignPlatform]] = UNSET, search: Union[Unset, None, str] = UNSET, order_by: Union[Unset, None, str] = "createdAt.desc", limit: Union[Unset, None, int] = 50, offset: Union[Unset, None, int] = 0, ) -> Response[Union[HTTPValidationError, LimitOffsetPageMetaCampaign]]: """Search Campaigns Args: vendor_id (Union[Unset, None, int]): Label id subaccount_id (Union[Unset, None, int]): Label subaccount id global_participant_ids (Union[Unset, None, List[str]]): Artist ids statuses (Union[Unset, None, List[CampaignStatus]]): Statuses objectives (Union[Unset, None, List[CampaignObjective]]): Objectives platforms (Union[Unset, None, List[CampaignPlatform]]): Platforms search (Union[Unset, None, str]): A search term order_by (Union[Unset, None, str]): Order by field(s) Default: 'createdAt.desc'. limit (Union[Unset, None, int]): Page size limit Default: 50. offset (Union[Unset, None, int]): Page offset Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: Response[Union[HTTPValidationError, LimitOffsetPageMetaCampaign]] """ kwargs = _get_kwargs( client=client, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_ids=global_participant_ids, statuses=statuses, objectives=objectives, platforms=platforms, search=search, order_by=order_by, limit=limit, offset=offset, ) response = httpx.request( verify=client.verify_ssl, **kwargs, ) return _build_response(client=client, response=response) def sync( *, client: AuthenticatedClient, vendor_id: Union[Unset, None, int] = UNSET, subaccount_id: Union[Unset, None, int] = UNSET, global_participant_ids: Union[Unset, None, List[str]] = UNSET, statuses: Union[Unset, None, List[CampaignStatus]] = UNSET, objectives: Union[Unset, None, List[CampaignObjective]] = UNSET, platforms: Union[Unset, None, List[CampaignPlatform]] = UNSET, search: Union[Unset, None, str] = UNSET, order_by: Union[Unset, None, str] = "createdAt.desc", limit: Union[Unset, None, int] = 50, offset: Union[Unset, None, int] = 0, ) -> Optional[Union[HTTPValidationError, LimitOffsetPageMetaCampaign]]: """Search Campaigns Args: vendor_id (Union[Unset, None, int]): Label id subaccount_id (Union[Unset, None, int]): Label subaccount id global_participant_ids (Union[Unset, None, List[str]]): Artist ids statuses (Union[Unset, None, List[CampaignStatus]]): Statuses objectives (Union[Unset, None, List[CampaignObjective]]): Objectives platforms (Union[Unset, None, List[CampaignPlatform]]): Platforms search (Union[Unset, None, str]): A search term order_by (Union[Unset, None, str]): Order by field(s) Default: 'createdAt.desc'. limit (Union[Unset, None, int]): Page size limit Default: 50. offset (Union[Unset, None, int]): Page offset Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: Union[HTTPValidationError, LimitOffsetPageMetaCampaign] """ return sync_detailed( client=client, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_ids=global_participant_ids, statuses=statuses, objectives=objectives, platforms=platforms, search=search, order_by=order_by, limit=limit, offset=offset, ).parsed async def asyncio_detailed( *, client: AuthenticatedClient, vendor_id: Union[Unset, None, int] = UNSET, subaccount_id: Union[Unset, None, int] = UNSET, global_participant_ids: Union[Unset, None, List[str]] = UNSET, statuses: Union[Unset, None, List[CampaignStatus]] = UNSET, objectives: Union[Unset, None, List[CampaignObjective]] = UNSET, platforms: Union[Unset, None, List[CampaignPlatform]] = UNSET, search: Union[Unset, None, str] = UNSET, order_by: Union[Unset, None, str] = "createdAt.desc", limit: Union[Unset, None, int] = 50, offset: Union[Unset, None, int] = 0, ) -> Response[Union[HTTPValidationError, LimitOffsetPageMetaCampaign]]: """Search Campaigns Args: vendor_id (Union[Unset, None, int]): Label id subaccount_id (Union[Unset, None, int]): Label subaccount id global_participant_ids (Union[Unset, None, List[str]]): Artist ids statuses (Union[Unset, None, List[CampaignStatus]]): Statuses objectives (Union[Unset, None, List[CampaignObjective]]): Objectives platforms (Union[Unset, None, List[CampaignPlatform]]): Platforms search (Union[Unset, None, str]): A search term order_by (Union[Unset, None, str]): Order by field(s) Default: 'createdAt.desc'. limit (Union[Unset, None, int]): Page size limit Default: 50. offset (Union[Unset, None, int]): Page offset Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: Response[Union[HTTPValidationError, LimitOffsetPageMetaCampaign]] """ kwargs = _get_kwargs( client=client, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_ids=global_participant_ids, statuses=statuses, objectives=objectives, platforms=platforms, search=search, order_by=order_by, limit=limit, offset=offset, ) async with httpx.AsyncClient(verify=client.verify_ssl) as _client: response = await _client.request(**kwargs) return _build_response(client=client, response=response) async def asyncio( *, client: AuthenticatedClient, vendor_id: Union[Unset, None, int] = UNSET, subaccount_id: Union[Unset, None, int] = UNSET, global_participant_ids: Union[Unset, None, List[str]] = UNSET, statuses: Union[Unset, None, List[CampaignStatus]] = UNSET, objectives: Union[Unset, None, List[CampaignObjective]] = UNSET, platforms: Union[Unset, None, List[CampaignPlatform]] = UNSET, search: Union[Unset, None, str] = UNSET, order_by: Union[Unset, None, str] = "createdAt.desc", limit: Union[Unset, None, int] = 50, offset: Union[Unset, None, int] = 0, ) -> Optional[Union[HTTPValidationError, LimitOffsetPageMetaCampaign]]: """Search Campaigns Args: vendor_id (Union[Unset, None, int]): Label id subaccount_id (Union[Unset, None, int]): Label subaccount id global_participant_ids (Union[Unset, None, List[str]]): Artist ids statuses (Union[Unset, None, List[CampaignStatus]]): Statuses objectives (Union[Unset, None, List[CampaignObjective]]): Objectives platforms (Union[Unset, None, List[CampaignPlatform]]): Platforms search (Union[Unset, None, str]): A search term order_by (Union[Unset, None, str]): Order by field(s) Default: 'createdAt.desc'. limit (Union[Unset, None, int]): Page size limit Default: 50. offset (Union[Unset, None, int]): Page offset Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: Union[HTTPValidationError, LimitOffsetPageMetaCampaign] """ return ( await asyncio_detailed( client=client, vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_ids=global_participant_ids, statuses=statuses, objectives=objectives, platforms=platforms, search=search, order_by=order_by, limit=limit, offset=offset, ) ).parsed