
    L^i                     t   d dl Z d dlZd dlmZ d dlZd dlmZ d dlmZmZm	Z	m
Z
mZ d dlmZmZmZmZmZmZmZ d Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd ZdZdZd Zd Z d[dZ!d Z"d Z#d Z$d Z%d Z&d Z'd Z(d Z)d Z*d Z+	 d\d Z,d! Z-d]d"Z.d# Z/d]d$Z0d% Z1d& Z2d' Z3d( Z4d) Z5d* Z6d+ Z7d, Z8d- Z9d. Z:d/ Z;d0 Z<d1 Z=d2 Z>d3 Z?d4 Z@d5 ZAd6 ZBd7 ZCd8 ZDd9 ZEd: ZFd; ZGd< ZHd= ZId> ZJd? ZKd@ ZLdA ZMdB ZNdC ZOdD ZPdE ZQdF ZRdG ZSdH ZTdI ZUdJ ZVdK ZWdL ZXdM ZYdN ZZdO Z[dP Z\dQ Z]dZdRZ^dZdSZ_dT Z`dU ZadV ZbdW ZcdX ZddZdYZedS )^    N)string_types)utils)call_metadata_apicall_metadata_rules_apicall_apicall_json_api_call_v2_api)
BadRequestAuthorizationRequired
NotAllowedNotFoundAlreadyExistsRateLimitedGeneralErrorc                  "    t          ddgi fi | S )a&  
    Tests the reachability of the Cloudinary API.

    See: https://cloudinary.com/documentation/admin_api#ping_cloudinary_servers

    :param options: Additional optional configuration parameters (none currently recognized).

    :return: The result of the API call.
    :rtype: Response
    getpingr   optionss    1D:\Nbitz\venv\Lib\site-packages\cloudinary/api.pyr   r      s      "88888    c                      |                      dd          }dg}|rCt          |t          j                  rt	          j        |          }|                    |           t          d|i fi | S )a  
    Get account usage details.

    Get a report on the status of your Cloudinary account usage details, including storage, credits, bandwidth,
    requests, number of resources, and add-on usage. Note that numbers are updated periodically.

    See: https://cloudinary.com/documentation/admin_api#get_product_environment_usage_details

    :param options: Additional optional parameters.
    :keyword date: The date for usage details (string in "YYYY-MM" format or a datetime.date object).
                   If omitted, returns usage for the current billing period.
    :type date: str or datetime.date

    :return: Detailed usage information
    :rtype: Response
    dateNusager   )pop
isinstancedatetimer   r   encode_date_to_usage_api_formatappendr   )r   r   uris      r   r   r   +   sv    " ;;vt$$D)C dHM** 	?8>>D

4R337333r   c                  B    t          | d          }t          ddg|fi | S )a  
    Get account config details.

    Fetches the account's configuration details with optional settings.

    See: https://cloudinary.com/documentation/admin_api#get_product_environment_config_details

    :param options: The optional parameters for the API request.
    :keyword bool settings: When True, returns extended settings in the response (if available).
    :return: Detailed config information.
    :rtype: Response
    settingsr   configonlyr   r   paramss     r   r$   r$   E   s/     ':&&F
F>>g>>>r   c                  "    t          ddgi fi | S )a"  
    Retrieves the types of resources (assets) available.

    See: https://cloudinary.com/documentation/admin_api#get_resources

    :param options: Additional optional configuration parameters (none currently recognized).
    :return: The result of the API call.
    :rtype: Response
    r   	resourcesr   r   s    r   resource_typesr+   V   s      r==W===r   c                     |                      dd          }|                      dd          }d|g}|r|                    |           t          d	i | }|                    t	          | dd                     t          d||fi | S )
a  
    Retrieves resources (assets) based on the provided options.

    See: https://cloudinary.com/documentation/admin_api#get_resources

    :param options: Additional options to filter the resources.
    :keyword str resource_type: The type of the resources. Defaults to "image".
    :keyword str type: The specific asset type. Defaults to None (not added to URI).
    :keyword str prefix: Return only resources with a public ID (or folder) that starts with this prefix.
    :keyword str start_at: Return resources updated since the specified timestamp (format: "yyyy-mm-dd hh:mm:ss").
    :keyword str direction: Return resources sorted by "asc" or "desc" order of creation.
    :keyword str next_cursor: A string that is returned as part of the response when there are more results to retrieve.
    :keyword int max_results: Maximum number of resources to return. Default=10.
    :return: The result of the API call.
    :rtype: Response
    resource_typeimagetypeNr*   prefixstart_atr    )r   r    __list_resources_paramsupdater&   r   r   r-   upload_typer!   r(   s        r   r*   r*   c   s    " KK99M++fd++K
&C  

;$//w//F
MM$w*55666V77w777r   c                 p    |                     dd          }d|d| g}t          di |}t          d||fi |S )a  
    Lists resources (assets) with the specified tag.

    This method does not return matching deleted assets, even if they have been backed up.

    See: https://cloudinary.com/documentation/admin_api#get_resources_by_tag

    :param tag: The tag value.
    :type tag: str
    :param options: Additional options to filter the resources.
    :keyword str resource_type: The type of the resources. Defaults to "image".
    :keyword str direction: Return resources in "asc" or "desc" order (by creation).
    :keyword int max_results: Maximum number of resources to return. Default=10.
    :keyword str next_cursor: A string returned when there are more results to fetch.
    :return: The result of the API call.
    :rtype: Response
    r-   r.   r*   tagsr   r2   r   r3   r   tagr   r-   r!   r(   s        r   resources_by_tagr<   ~   sR    $ KK99Mvs
3C$//w//FV77w777r   c                 r    |                     dd          }d|d| |g}t          di |}t          d||fi |S )a  
    Lists resources (assets) currently in the specified moderation queue and status.

    See: https://cloudinary.com/documentation/admin_api#get_resources_in_moderation

    :param kind: Type of image moderation queue to list (e.g., "manual", "webpurify", "aws_rek", "metascan").
    :type kind: str
    :param status: Only assets with this moderation status will be returned.
                   Valid values: "pending", "approved", "rejected".
    :type status: str
    :param options: Additional options to filter the resources.
    :keyword str resource_type: The type of the resources. Defaults to "image".
    :keyword str direction: Return resources in "asc" or "desc" order (by creation).
    :keyword int max_results: Maximum number of resources to return. Default=10.
    :keyword str next_cursor: A string returned when there are more results to fetch.
    :return: The result of the API call.
    :rtype: Response
    r-   r.   r*   moderationsr   r2   r9   )kindstatusr   r-   r!   r(   s         r   resources_by_moderationrA      sT    & KK99M}dF
CC$//w//FV77w777r   c                     |                     dd          }|                     dd          }d||g}t          t          di ||           }t          d||fi |S )	a  
    Lists resources (assets) with the specified public IDs.

    See: https://cloudinary.com/documentation/admin_api#get_resources

    :param public_ids: The requested public_ids (up to 100).
    :type public_ids: list[str]
    :param options: The optional parameters.
    :keyword str resource_type: The type of the resources. Defaults to "image".
    :keyword str type: The specific asset type. Defaults to "upload".
    :keyword str direction: Return resources in "asc" or "desc" order.
    :keyword int max_results: Maximum number of resources to return.
    :keyword str next_cursor: A string returned when there are more results to fetch.
    :return: The result of the API call.
    :rtype: Response
    r-   r.   r/   uploadr*   
public_idsr   r2   )r   dict__resources_paramsr   rE   r   r-   r6   r!   r(   s         r   resources_by_idsrI      sq    " KK99M++fh//K{
3C$//w//JGGGFV77w777r   c                 J    ddg}t          di |}| |d<   t          d||fi |S )av  
    Returns the details of the resources (assets) under a specified asset_folder.

    See: https://cloudinary.com/documentation/admin_api#get_resources_by_asset_folder

    :param asset_folder: The Asset Folder of the asset.
    :type asset_folder: str
    :param options: Additional options to filter the resources.
    :keyword str direction: Return resources in "asc" or "desc" order.
    :keyword int max_results: Maximum number of resources to return.
    :keyword str next_cursor: A string returned when there are more results to fetch.
    :return: Resources (assets) of a specific asset_folder.
    :rtype: Response
    r*   by_asset_folderasset_folderr   r2   )r3   r   )rL   r   r!   r(   s       r   resources_by_asset_folderrM      sF     )
*C$//w//F)F>V77w777r   c                 ^    ddg}t          t          di ||           }t          d||fi |S )a  
    Retrieves the resources (assets) indicated in the asset IDs.
    This method does not return deleted assets even if they have been backed up.

    See: https://cloudinary.com/documentation/admin_api#get_resources_by_asset_ids

    :param asset_ids: The requested asset IDs.
    :type asset_ids: list[str]
    :param options: Additional options to filter the resources.
    :keyword str direction: Return resources in "asc" or "desc" order.
    :keyword int max_results: Maximum number of resources to return.
    :keyword str next_cursor: A string returned when there are more results to fetch.
    :return: Resources (assets) as indicated in the asset IDs.
    :rtype: Response
    r*   by_asset_ids	asset_idsr   r2   )rF   rG   r   rQ   r   r!   r(   s       r   resources_by_asset_idsrS      sI      
'C$//w//9EEEFV77w777r   c                     |                     dd          }d|dg}t          d	i |}| |d<   |||d<   t          d||fi |S )
ao  
    Retrieves resources (assets) with a specified context key.
    This method does not return deleted assets even if they have been backed up.

    See: https://cloudinary.com/documentation/admin_api#get_resources_by_context

    :param key: Only assets with this context key are returned.
    :type key: str
    :param value: Only assets with this value for the context key are returned.
    :type value: str, optional
    :param options: Additional options to filter the resources.
    :keyword str resource_type: The type of the resources. Defaults to "image".
    :keyword str direction: Return resources in "asc" or "desc" order.
    :keyword int max_results: Maximum number of resources to return.
    :keyword str next_cursor: A string returned when there are more results to fetch.
    :return: Resources (assets) with a specified context key.
    :rtype: Response
    r-   r.   r*   contextkeyNvaluer   r2   r9   )rV   rW   r   r-   r!   r(   s         r   resources_by_contextrX      sh    & KK99My
1C$//w//FF5MwV77w777r   c                      t          | dddd          }|                     d          r/t          j        t          j        | d                             |d<   |S )
    Prepares optional parameters for resources_* API calls.

    :param options: Additional options
    :return: Optional parameters
    :rtype: dict
    :internal
    r8   rU   metadatar>   fields)r&   r   r   encode_listbuild_arrayr'   s     r   rG   rG     sX     '69j-HHF{{8 S ,U->wx?P-Q-QRRxMr   c                  h    t          di | }|                    t          | ddd                     |S )rZ   next_cursormax_results	directionr2   )rG   r4   r&   )r   resources_paramss     r   r3   r3     s@     *44G44D-TTUUUr   c                 \    ddg}| ||t          j        |d          d}t          d||fi |S )a  
    Find images based on their visual content.

    See: https://cloudinary.com/documentation/admin_api#visual_search_for_resources

    :param image_url: The URL of an image.
    :type image_url: str, optional
    :param image_asset_id: The asset_id of an image in your account.
    :type image_asset_id: str, optional
    :param text: A textual description (e.g. "cat").
    :type text: str, optional
    :param image_file: The image file. (str|callable|Path|bytes)
    :type image_file: str or callable or Path or bytes, optional
    :param options: Additional optional parameters to pass along.

    :return: Resources (assets) that were found
    :rtype: Response
    r*   visual_searchfile)	image_urlimage_asset_idtext
image_filepost)r   handle_file_parameterr   )rg   rh   ri   rj   r   r!   r(   s          r   re   re   +  sO    & 
(C(1*fEE	 F FC337333r   c                     |                     dd          }|                     dd          }d||| g}t          di |}t          d||fi |S )a  
    Returns the details of the specified asset and all its derived assets (by public ID).

    See: https://cloudinary.com/documentation/admin_api#get_details_of_a_single_resource_by_public_id

    :param public_id: The public ID of the resource.
    :type public_id: str
    :param options: Additional optional parameters for retrieval.
    :keyword str resource_type: The resource type (e.g. "image", "raw").
    :keyword str type: The asset's storage type (e.g. "upload").
    :keyword bool exif: Whether to return Exif metadata.
    :keyword bool faces: Whether to return face coordinates.
    :keyword bool colors: Whether to return color information.
    :keyword bool image_metadata: Whether to return image metadata.
    :keyword bool media_metadata: Whether to return extended media metadata.
    :keyword bool cinemagraph_analysis: Whether to include cinemagraph analysis data.
    :keyword bool pages: Whether to include the page count of multi-page files.
    :keyword bool phash: Whether to include perceptual hash data.
    :keyword bool coordinates: Whether to return custom and face coordinates.
    :keyword int max_results: The maximum number of derived resources to return.
    :keyword bool quality_analysis: Whether to include quality analysis data.
    :keyword str derived_next_cursor: A pagination cursor for derived resources.
    :keyword bool accessibility_analysis: Whether to include accessibility analysis data.
    :keyword bool versions: Whether to include version information for the asset.
    :keyword bool related: Whether to include related assets.
    :keyword str related_next_cursor: A pagination cursor for related assets.
    :return: The result of the API call.
    :rtype: Response
    r-   r.   r/   rC   r*   r   r2   )r   _prepare_asset_details_paramsr   	public_idr   r-   r6   r!   r(   s         r   resourcerq   H  se    < KK99M++fh//K{I
>C*55W55FV77w777r   c                 @    d| g}t          di |}t          d||fi |S )a<  
    Returns the details of the specified asset and all its derived assets (by asset ID).

    See: https://cloudinary.com/documentation/admin_api#get_details_of_a_single_resource_by_asset_id

    :param asset_id: The Asset ID of the asset
    :type asset_id: str
    :param options: Additional optional parameters for retrieval.
    :keyword bool exif: Whether to return Exif metadata.
    :keyword bool faces: Whether to return face coordinates.
    :keyword bool colors: Whether to return color information.
    :keyword bool image_metadata: Whether to return image metadata.
    :keyword bool media_metadata: Whether to return extended media metadata.
    :keyword bool cinemagraph_analysis: Whether to include cinemagraph analysis data.
    :keyword bool pages: Whether to include the page count of multi-page files.
    :keyword bool phash: Whether to include perceptual hash data.
    :keyword bool coordinates: Whether to return custom and face coordinates.
    :keyword int max_results: The maximum number of derived resources to return.
    :keyword bool quality_analysis: Whether to include quality analysis data.
    :keyword str derived_next_cursor: A pagination cursor for derived resources.
    :keyword bool accessibility_analysis: Whether to include accessibility analysis data.
    :keyword bool versions: Whether to include version information for the asset.
    :keyword bool related: Whether to include related assets.
    :keyword str related_next_cursor: A pagination cursor for related assets.
    :return: Resource (asset) of a specific asset_id
    :rtype: Response
    r*   r   r2   )rn   r   )asset_idr   r!   r(   s       r   resource_by_asset_idrt   m  s;    8 
!C*55W55FV77w777r   c                  @    t          | ddddddddd	d
dddddd          S )z
    Prepares optional parameters for resource_by_asset_id or resource_by_public_id API calls.

    :param options: Additional options
    :return: Optional parameters
    :rtype: dict
    :internal
    exiffacescolorsimage_metadatamedia_metadatacinemagraph_analysispagesphashcoordinatesra   quality_analysisderived_next_cursoraccessibility_analysisversionsrelatedrelated_next_cursorr&   r   s    r   rn   rn     sC     (4DFVXn-@RTi(*iAVX X Xr   c                    |                     dd          }|                     dd          }d||| g}t          |dddd	d
dddd
  
        }d|v r0d                    t          j        |d                             |d<   d|v r*t          j        |                    d                    |d<   d|v r*t          j        |                    d                    |d<   d|v r*t          j        |                    d                    |d<   d|v r*t          j        |                    d                    |d<   d|v r*t          j        |                    d                    |d<   d|v r%t          |                    d                    |d<   d|v r<t          j        t          j
        |                    d                              |d<   d|v r|                    d          |d<   d|v r|                    d          |d<   d|v r|                    d          |d<   d|v r|                    d          |d<   t          d||fi |S )a@  
    Updates the details of a specified resource by public ID.

    See: https://cloudinary.com/documentation/admin_api#update_details_of_an_existing_resource

    :param public_id: The public ID of the resource to update.
    :type public_id: str
    :param options: Additional options for the update operation.
    :keyword str resource_type: The resource type (e.g. "image", "raw").
    :keyword str type: The asset's storage type (e.g. "upload").
    :keyword str moderation_status: Sets the moderation status ("approved" / "rejected").
    :keyword str raw_convert: Requests raw file conversion ("aspose", etc.).
    :keyword str quality_override: Overrides the quality setting.
    :keyword str ocr: Requests OCR extraction ("adv_ocr").
    :keyword str categorization: Sets the categorization mode (e.g. "google_tagging").
    :keyword str detection: Sets the detection mode (e.g. "adv_face").
    :keyword str similarity_search: Reserved for similarity search tasks.
    :keyword str background_removal: The background removal setting (e.g. "cloudinary_ai" or "pixelz").
    :keyword str notification_url: A URL for receiving notifications.
    :keyword list tags: The tags to assign to the asset.
    :keyword list or str face_coordinates: The face coordinates to set.
    :keyword list or str custom_coordinates: The custom coordinates to set.
    :keyword list regions: Region data for partial image transformations.
    :keyword dict context: Contextual (key/value) metadata.
    :keyword dict metadata: Structured metadata.
    :keyword float auto_tagging: A float from 0.0 to 1.0. If set, automatically tags an image.
    :keyword list access_control: An array of access control rules in dictionary form.
    :keyword str asset_folder: The folder path in which to place the asset.
    :keyword str display_name: A user-friendly name for the asset.
    :keyword bool unique_display_name: If True, ensures the display name is unique.
    :keyword bool clear_invalid: If True, removes or corrects invalid data (e.g., invalid context).
    :return: The result of the API call.
    :rtype: Response
    r-   r.   r/   rC   r*   moderation_statusraw_convertquality_overrideocrcategorization	detectionsimilarity_searchbackground_removalnotification_urlr8   ,face_coordinatescustom_coordinatesregionsrU   r[   auto_taggingaccess_controlrL   display_nameunique_display_nameclear_invalidrk   )r   r&   joinr   r^   encode_double_arrayr   json_encodeencode_contextstrbuild_list_of_dictsr   ro   s         r   r4   r4     su   F KK99M++fh//K{I
>C'.$e"K1D&(:< <F %"3GFO"D"DEEvW$$%*%>w{{K]?^?^%_%_!"w&&','@MaAbAb'c'c#$G!-gkk).D.DEEyG!0Y1G1GHHyW"1'++j2I2IJJz  !$W[[%@%@!A!A~7""#(#4U5Nw{{[kOlOl5m5m#n#n   !(^!<!<~  !(^!<!<~''(/4I(J(J$%'!!")++o">">f88888r   c                     |                     dd          }|                     dd          }d||g}t          ||           }t          d||fi |S )a1  
    Deletes resources (assets) given their public IDs.

    The resources must belong to the specified resource_type and type.

    See: https://cloudinary.com/documentation/admin_api#delete_resources

    :param public_ids: The public IDs of the resources to delete.
    :type public_ids: list[str]
    :param options: Additional options.
    :keyword str resource_type: Defaults to "image".
    :keyword str type: Defaults to "upload".
    :keyword list transformations: The derived transformations to delete (if any).
    :keyword bool keep_original: When True, keeps the original resource.
    :keyword str next_cursor: A string returned when more results are available.
    :keyword bool invalidate: When True, invalidates the assets on the CDN.
    :return: The result of the command.
    :rtype: Response
    r-   r.   r/   rC   r*   rD   deleter   __delete_resource_paramsr   rH   s         r   delete_resourcesr     sb    ( KK99M++fh//K{
3C%g*EEEF3::':::r   c                 H    dg}t          ||           }t          d||fi |S )a  
    Deletes resources (assets) by asset IDs.

    See: https://cloudinary.com/documentation/admin_api#delete_resources_by_asset_id

    :param asset_ids: The asset IDs of the assets to delete.
    :type asset_ids: list[str]
    :param options: Additional options.
    :keyword list transformations: The derived transformations to delete (if any).
    :keyword bool keep_original: When True, keeps the original resource.
    :keyword str next_cursor: A string returned when more results are available.
    :keyword bool invalidate: When True, invalidates the assets on the CDN.
    :return: The result of the command.
    :rtype: dict
    r*   rP   r   )r   r   rR   s       r   delete_resources_by_asset_idsr     s7      -C%gCCCF3::':::r   c                     |                     dd          }|                     dd          }d||g}t          ||           }t          d||fi |S )a  
    Deletes resources (assets) that have a specified prefix for their Public IDs.

    See: https://cloudinary.com/documentation/admin_api#delete_resources

    :param prefix: The prefix of the Public IDs to delete.
    :type prefix: str
    :param options: Additional options.
    :keyword str resource_type: Defaults to "image".
    :keyword str type: Defaults to "upload".
    :keyword list transformations: The derived transformations to delete (if any).
    :keyword bool keep_original: When True, keeps the original resource.
    :keyword str next_cursor: A string returned when more results are available.
    :keyword bool invalidate: When True, invalidates the assets on the CDN.
    :return: The result of the command.
    :rtype: Response
    r-   r.   r/   rC   r*   r0   r   r   )r0   r   r-   r6   r!   r(   s         r   delete_resources_by_prefixr     sb    $ KK99M++fh//K{
3C%gf===F3::':::r   c                      |                      dd          }|                      dd          }d||g}t          | d          }t          d||fi | S )	aJ  
    Deletes **all** resources (assets) of a specified resource_type and type.

    Use with caution: This removes all matching resources from your account.

    See: https://cloudinary.com/documentation/admin_api#delete_resources

    :param options: Additional options.
    :keyword str resource_type: Defaults to "image".
    :keyword str type: Defaults to "upload".
    :keyword list transformations: The derived transformations to delete (if any).
    :keyword bool keep_original: When True, keeps the original resource.
    :keyword str next_cursor: A string returned when more results are available.
    :keyword bool invalidate: When True, invalidates the assets on the CDN.
    :keyword bool all: (Added internally) If True, indicates all resources are to be deleted.
    :return: The result of the command.
    :rtype: Response
    r-   r.   r/   rC   r*   T)allr   r   r5   s        r   delete_all_resourcesr   +  sb    & KK99M++fh//K{
3C%g4888F3::':::r   c                 v    |                     dd          }d|d| g}t          |          }t          d||fi |S )a  
    Deletes resources (assets) that contain a specified tag.

    See: https://cloudinary.com/documentation/admin_api#delete_resources_by_tags

    :param tag: The tag whose associated resources should be deleted.
    :type tag: str
    :param options: Additional options.
    :keyword str resource_type: Defaults to "image".
    :keyword list transformations: The derived transformations to delete (if any).
    :keyword bool keep_original: When True, keeps the original resource.
    :keyword str next_cursor: A string returned when more results are available.
    :keyword bool invalidate: When True, invalidates the assets on the CDN.
    :return: The result of the command.
    :rtype: Response
    r-   r.   r*   r8   r   r   r:   s        r   delete_resources_by_tagr   E  sL    " KK99Mvs
3C%g..F3::':::r   c                 .    dg}d| i}t          d||fi |S )a  
    Deletes derived resources by their derived resource IDs.

    See: https://cloudinary.com/documentation/admin_api#delete_derived_resources

    :param derived_resource_ids: A list of derived resource IDs.
    :type derived_resource_ids: list[str]
    :param options: Additional optional parameters (none currently recognized).
    :return: The result of the command.
    :rtype: Response
    derived_resourcesderived_resource_idsr   r   )r   r   r!   r(   s       r   delete_derived_resourcesr   \  s1     
C$&:;F3::':::r   r.   rC   c                     d||g}t          | t                    s| g} | t          j        |          dd}|||d<   t	          d||fi |S )a  
    Deletes derived resources of public IDs, identified by transformations.

    See: https://cloudinary.com/documentation/admin_api#delete_derived_resources

    :param public_ids: The base resources (list of public IDs).
    :type public_ids: list[str]
    :param transformations: The transformations of derived resources, optionally including the format.
    :type transformations: list[dict or str]
    :param resource_type: The type of the resource. Defaults to "image".
    :type resource_type: str
    :param type: The upload type. Defaults to "upload".
    :type type: str
    :param invalidate: (optional) True to invalidate the resources after deletion.
    :type invalidate: bool, optional
    :param options: Additional optional parameters (none currently recognized).
    :return: The result of the command, including the public IDs for which derived resources were deleted.
    :rtype: dict
    r*   T)rE   transformationskeep_originalN
invalidater   )r   listr   build_eagerr   )rE   r   r-   r/   r   r   r!   r(   s           r    delete_derived_by_transformationr   m  su    , t
,Cj$'' " \
  ,_== F
 )|3::':::r   c                 V    dd| g}dt          j        |          i}t          d||fi |S )a  
    Deletes backed up versions of a resource by asset IDs.

    See: https://cloudinary.com/documentation/admin_api#delete_backed_up_versions_of_a_resource

    :param asset_id: The asset ID of the asset to update.
    :type asset_id: str
    :param version_ids: The array of version IDs.
    :type version_ids: list[str]
    :param options: Additional optional parameters (none currently recognized).
    :return: The result of the command.
    :rtype: dict
    r*   backupversion_idsr   r   r^   r   )rs   r   r   r!   r(   s        r   delete_backed_up_assetsr     s?     (
+CU.{;;<F3::':::r   c                 Z    dd||| g}dt          j        |          i}t          d||fi |S )a  
    Relates an asset to other assets by public IDs.

    See: https://cloudinary.com/documentation/admin_api#add_related_assets

    :param public_id: The public ID of the asset to update.
    :type public_id: str
    :param assets_to_relate: Array of up to 10 fully_qualified_public_ids as resource_type/type/public_id.
    :type assets_to_relate: list[str]
    :param resource_type: The type of the resource. Defaults to "image".
    :type resource_type: str
    :param type: The upload type. Defaults to "upload".
    :type type: str
    :param options: Additional optional parameters (none currently recognized).
    :return: The result of the command.
    :rtype: dict
    r*   related_assetsassets_to_relaterk   r   )rp   r   r-   r/   r   r!   r(   s          r   add_related_assetsr     sE    $ (-y
IC %"34D"E"EFFf88888r   c                 V    dd| g}dt          j        |          i}t          d||fi |S )a  
    Relates an asset to other assets by asset IDs.

    See: https://cloudinary.com/documentation/admin_api#add_related_assets_by_asset_id

    :param asset_id: The asset ID of the asset to update.
    :type asset_id: str
    :param assets_to_relate: The array of up to 10 asset IDs.
    :type assets_to_relate: list[str]
    :param options: Additional optional parameters (none currently recognized).
    :return: The result of the command.
    :rtype: dict
    r*   r   r   rk   r   )rs   r   r   r!   r(   s        r   add_related_assets_by_asset_idsr     sA     ((
3C %"34D"E"EFFf88888r   c                 Z    dd||| g}dt          j        |          i}t          d||fi |S )a  
    Unrelates an asset from other assets by public IDs.

    See: https://cloudinary.com/documentation/admin_api#delete_related_assets

    :param public_id: The public ID of the asset to update.
    :type public_id: str
    :param assets_to_unrelate: Array of up to 10 fully_qualified_public_ids as resource_type/type/public_id.
    :type assets_to_unrelate: list[str]
    :param resource_type: The type of the resource. Defaults to "image".
    :type resource_type: str
    :param type: The upload type. Defaults to "upload".
    :type type: str
    :param options: Additional optional parameters (none currently recognized).
    :return: The result of the command.
    :rtype: dict
    r*   r   assets_to_unrelater   r   )rp   r   r-   r/   r   r!   r(   s          r   delete_related_assetsr     sE    $ (-y
IC"E$56H$I$IJF3::':::r   c                 V    dd| g}dt          j        |          i}t          d||fi |S )a  
    Unrelates an asset from other assets by asset IDs.

    See: https://cloudinary.com/documentation/admin_api#delete_related_assets_by_asset_id

    :param asset_id: The asset ID of the asset to update.
    :type asset_id: str
    :param assets_to_unrelate: The array of up to 10 asset IDs.
    :type assets_to_unrelate: list[str]
    :param options: Additional optional parameters (none currently recognized).
    :return: The result of the command.
    :rtype: dict
    r*   r   r   r   r   )rs   r   r   r!   r(   s        r   "delete_related_assets_by_asset_idsr     sA     ((
3C"E$56H$I$IJF3::':::r   c            
      t    |                      dd          }d|g}t          d|t          | ddd          fi | S )a  
    Lists all the tags currently used for a specified asset type.

    See: https://cloudinary.com/documentation/admin_api#get_tags

    :param options: The optional parameters.
    :keyword str resource_type: Defaults to "image".
    :keyword str prefix: Return only tags that begin with the specified prefix.
    :keyword int max_results: Maximum number of tags to return.
    :keyword str next_cursor: A string returned when more results are available.
    :return: The result of the API call.
    :rtype: Response
    r-   r.   r8   r   r`   ra   r0   )r   r   r&   )r   r-   r!   s      r   r8   r8     sK     KK99M=
!CT'=-QY%Z%Zff^efffr   c                  J    dg}t          | ddd          }t          d||fi | S )a  
    Lists all transformations.

    See: https://cloudinary.com/documentation/admin_api#get_transformations

    :param options: The optional parameters.
    :keyword bool named: When True, return only named transformations.
    :keyword str next_cursor: A string returned when more results are available.
    :keyword int max_results: Maximum number of transformations to return.
    :return: The list of transformations.
    :rtype: Response
    r   namedr`   ra   r   r%   r   r!   r(   s      r   r   r   
  s9     
C'7M=AAFV77w777r   c                 v    dg}t          |dd          }t          j        |           |d<   t          d||fi |S )a  
    Returns the details of a single transformation.

    See: https://cloudinary.com/documentation/admin_api#get_transformation_details

    :param transformation: The transformation to retrieve (string or dict).
    :type transformation: str or dict
    :param options: The optional parameters.
    :keyword str next_cursor: A string returned when more results are available.
    :keyword int max_results: Maximum number of derived assets to return.
    :return: The transformation details.
    :rtype: Response
    r   r`   ra   transformationr   )r&   r   build_single_eagerr   r   r   r!   r(   s       r   r   r     sM     
C'=-88F$7GGFV77w777r   c                 R    dg}dt          j        |           i}t          d||fi |S )ae  
    Deletes a transformation.

    See: https://cloudinary.com/documentation/admin_api#delete_transformation

    :param transformation: The transformation to delete (string or dict).
    :type transformation: str or dict
    :param options: Additional options (none currently recognized).
    :return: The result of the API call.
    :rtype: Response
    r   r   r   r   r   r   r   s       r   delete_transformationr   0  s;     
C 8 H HIF3::':::r   c                     dg}t          |d          }d|v r%t          |                    d                    |d<   t          j        |           |d<   t          d||fi |S )a  
    Updates a transformation.

    Currently, the only supported update is setting the "allowed_for_strict" flag
    and the "unsafe_update" transformation.

    See: https://cloudinary.com/documentation/admin_api#update_transformation

    :param transformation: The transformation to update (string or dict).
    :type transformation: str or dict
    :param options: Additional update options.
    :keyword bool allowed_for_strict: Whether the transformation is allowed in strict mode.
    :keyword dict or str unsafe_update: The transformation to associate under unsafe_update.
    :return: The result of the API call.
    :rtype: Response
    r   allowed_for_strictunsafe_updater   put)r&   transformation_stringr   r   r   r   )r   r   r!   updatess       r   update_transformationr   A  su    " 
C7011G'!!#8_9U9U#V#V  % 8 H HGW88888r   c                 T    dg}| t          j        |          d}t          d||fi |S )a  
    Creates a named transformation based on an existing transformation.

    See: https://cloudinary.com/documentation/admin_api#create_a_named_transformation

    :param name: The name of the transformation to create.
    :type name: str
    :param definition: The transformation definition (string or dict).
    :type definition: str or dict
    :param options: Additional options (none currently recognized).
    :return: The result of the API call.
    :rtype: Response
    r   )namer   rk   r   )r   
definitionr   r!   r(   s        r   create_transformationr   Z  s>     
Ce.Fz.R.RSSFf88888r   c                     |                     dd          }d|dg}t          t          |ddd          |           }t          d	||fi |S )
a  
    Publishes specific assets by their public IDs.

    :param public_ids: The list of public IDs to publish.
    :type public_ids: list[str]
    :param options: Additional options.
    :keyword str resource_type: The resource type (e.g. "image").
    :keyword str type: The asset type (e.g. "upload").
    :keyword bool overwrite: Whether to overwrite existing published assets.
    :keyword bool invalidate: Whether to invalidate the CDN.
    :return: The result of the publish operation.
    :rtype: Response
    r-   r.   r*   publish_resourcesr/   	overwriter   rD   rk   r   rF   r&   r   )rE   r   r-   r!   r(   s        r   publish_by_idsr   m  s^     KK99M':
;C$w\BBzZZZFf88888r   c                     |                     dd          }d|dg}t          t          |ddd          |           }t          d	||fi |S )
a  
    Publishes assets that have a specified prefix for their public IDs.

    :param prefix: The prefix of the public IDs to publish.
    :type prefix: str
    :param options: Additional options.
    :keyword str resource_type: The resource type (e.g. "image").
    :keyword str type: The asset type (e.g. "upload").
    :keyword bool overwrite: Whether to overwrite existing published assets.
    :keyword bool invalidate: Whether to invalidate the CDN.
    :return: The result of the publish operation.
    :rtype: Response
    r-   r.   r*   r   r/   r   r   r   rk   r   )r0   r   r-   r!   r(   s        r   publish_by_prefixr     s^     KK99M':
;C$w\BB6RRRFf88888r   c                     |                     dd          }d|dg}t          t          |ddd          |           }t          d	||fi |S )
a  
    Publishes assets that contain a specified tag.

    :param tag: The tag whose associated resources should be published.
    :type tag: str
    :param options: Additional options.
    :keyword str resource_type: The resource type (e.g. "image").
    :keyword str type: The asset type (e.g. "upload").
    :keyword bool overwrite: Whether to overwrite existing published assets.
    :keyword bool invalidate: Whether to invalidate the CDN.
    :return: The result of the publish operation.
    :rtype: Response
    r-   r.   r*   r   r/   r   r   )r;   rk   r   r:   s        r   publish_by_tagr     s^     KK99M':
;C$w\BBLLLFf88888r   c            	      D    dg}t          d|t          | dd          fi | S )ah  
    Lists all upload presets.

    See: https://cloudinary.com/documentation/admin_api#get_upload_presets

    :param options: Additional options.
    :keyword str next_cursor: A string returned when more results are available.
    :keyword int max_results: Maximum number of presets to return.
    :return: A list of upload presets.
    :rtype: Response
    upload_presetsr   r`   ra   r   r&   r   r!   s     r   r   r     s3     
CT'=-%P%P\\T[\\\r   c                 D    d| g}t          d|t          |d          fi |S )a  
    Retrieves the details of a single upload preset.

    See: https://cloudinary.com/documentation/admin_api#get_the_details_of_a_single_upload_preset

    :param name: The name of the upload preset.
    :type name: str
    :param options: Additional options.
    :keyword int max_results: Maximum number of details to return (if relevant).
    :return: The upload preset details.
    :rtype: Response
    r   r   ra   r   r   r   r!   s      r   upload_presetr     s2     T
"CT'=%A%AMMWMMMr   c                 (    d| g}t          d|i fi |S )aM  
    Deletes an upload preset by name.

    See: https://cloudinary.com/documentation/admin_api#delete_an_upload_preset

    :param name: The name of the upload preset to delete.
    :type name: str
    :param options: Additional options (none currently recognized).
    :return: The result of the deletion.
    :rtype: Response
    r   r   r   r   s      r   delete_upload_presetr     s(     T
"C366g666r   c                     d| g}t          j        di |}t          j        |          }|                    t	          |ddd                     t          d||fi |S )aK  
    Updates an existing upload preset.

    See: https://cloudinary.com/documentation/admin_api#update_an_upload_preset

    :param name: The name of the upload preset to update.
    :type name: str
    :param options: The parameters to update for the preset (e.g., folder, tags).
    :keyword bool unsigned: Whether this preset is unsigned (public).
    :keyword bool disallow_public_id: When True, the public ID cannot be overridden during upload.
    :keyword bool live: Whether this preset is for live (video) usage.
    :return: The updated upload preset.
    :rtype: Response
    r   unsigneddisallow_public_idliver   r2   r   build_upload_paramscleanup_paramsr4   r&   r   r   r   r!   r(   s       r   update_upload_presetr     so     T
"C&1111F!&))F
MM$w
,@&IIJJJV77w777r   c            	          dg}t          j        di | }t          j        |          }|                    t	          | dddd                     t          d||fi | S )a+  
    Creates a new upload preset.

    See: https://cloudinary.com/documentation/admin_api#create_an_upload_preset

    :param options: The parameters for the new preset (e.g., folder, tags).
    :keyword bool unsigned: Whether this preset is unsigned (public).
    :keyword bool disallow_public_id: When True, the public ID cannot be overridden during upload.
    :keyword str name: The name of the new upload preset.
    :keyword bool live: Whether this preset is for live (video) usage.
    :return: The created upload preset.
    :rtype: Response
    r   r   r   r   r   rk   r2   r   r   s      r   create_upload_presetr     so     
C&1111F!&))F
MM$w
,@&&QQRRRf88888r   c            	      @    t          ddgt          | dd          fi | S )a  
    Lists the top-level folders in your Cloudinary account.

    See: https://cloudinary.com/documentation/admin_api#get_root_folders

    :param options: Additional options.
    :keyword str next_cursor: A string returned when more results are available.
    :keyword int max_results: Maximum number of folders to return.
    :return: The list of top-level folders.
    :rtype: Response
    r   foldersr`   ra   r   r   s    r   root_foldersr     s-     T'=--X-Xdd\cdddr   c           	      B    t          dd| gt          |dd          fi |S )a  
    Lists the subfolders of a given folder path.

    See: https://cloudinary.com/documentation/admin_api#get_subfolders

    :param of_folder_path: The path of the parent folder.
    :type of_folder_path: str
    :param options: Additional options.
    :keyword str next_cursor: A string returned when more results are available.
    :keyword int max_results: Maximum number of folders to return.
    :return: The list of subfolders.
    :rtype: Response
    r   r   r`   ra   r   )of_folder_pathr   s     r   
subfoldersr    s1     N ;T'=Zg=h=httlstttr   c                 $    t          dd| gi fi |S )aD  
    Creates a folder at the specified path.

    See: https://cloudinary.com/documentation/admin_api#create_folder

    :param path: The path for the new folder.
    :type path: str
    :param options: Additional options (none currently recognized).
    :return: The result of the folder creation.
    :rtype: Response
    rk   r   r   )pathr   s     r   create_folderr  %  s#     )T!2BBB'BBBr   c                 ,    d|i}t          dd| g|fi |S )a  
    Renames a folder.

    See: https://cloudinary.com/documentation/admin_api#update_folder

    :param from_path: The full path of an existing asset folder.
    :type from_path: str
    :param to_path: The full path of the new asset folder.
    :type to_path: str
    :param options: Additional options (none currently recognized).
    :return: A response indicating the success or failure of the rename operation.
    :rtype: Response
    	to_folderr   r   r   )	from_pathto_pathr   r(   s       r   rename_folderr	  4  s-     7#FI 6JJ'JJJr   c                 D    t          |d          }t          dd| g|fi |S )a  
    Deletes a folder.

    The folder must be empty, but can have descendant empty subfolders.

    See: https://cloudinary.com/documentation/admin_api#delete_folder

    :param path: The folder to delete.
    :type path: str
    :param options: Additional options.
    :keyword bool skip_backup: Whether to skip backing up the folder before deletion.
    :return: A response indicating the success or failure of the delete operation.
    :rtype: Response
    skip_backupr   r   r%   )r  r   r(   s      r   delete_folderr  F  s2     '=))FIt#4fHHHHHr   c                     |                     dd          }|                     dd          }d||dg}t          d
d| it          |d          }t          d	||fi |S )a'  
    Restores deleted resources (assets) by public IDs, if backups are available.

    See: https://cloudinary.com/documentation/admin_api#restore_resources

    :param public_ids: The list of public IDs to restore.
    :type public_ids: list[str]
    :param options: Additional options, e.g., "versions".
    :keyword list[str] versions: A list of specific version IDs to restore.
    :keyword str resource_type: Defaults to "image".
    :keyword str type: Defaults to "upload".
    :return: The result of the restore operation.
    :rtype: dict
    r-   r.   r/   rC   r*   restorerE   r   rk   r2   r   rH   s         r   r  r  Y  st     KK99M++fh//K{I
>CEEZE4+D+DEEFf88888r   c                 `    ddg}t          dd| it          |d          }t          d||fi |S )a  
    Restores deleted resources (assets) by their asset IDs, if backups are available.

    See: https://cloudinary.com/documentation/admin_api#restore_resources_by_asset_id

    :param asset_ids: The asset IDs of the assets to restore.
    :type asset_ids: list[str]
    :param options: Additional options (e.g., versions).
    :keyword list[str] versions: A list of specific version IDs to restore.
    :return: The result of the restore operation.
    :rtype: dict
    r*   r  rQ   r   rk   r2   )rF   r&   r   rR   s       r   restore_by_asset_idsr  o  sJ     	
"CCCICgz)B)BCCFf88888r   c            	      D    dg}t          d|t          | dd          fi | S )a|  
    Lists all upload mappings in your account.

    See: https://cloudinary.com/documentation/admin_api#get_upload_mappings

    :param options: Additional options.
    :keyword str next_cursor: A string returned when more results are available.
    :keyword int max_results: Maximum number of mappings to return.
    :return: A list of upload mappings.
    :rtype: Response
    upload_mappingsr   r`   ra   r   r   s     r   r  r    s3     
CT'=-%P%P\\T[\\\r   c                 F    dg}t          |           }t          d||fi |S )ae  
    Retrieves a single upload mapping by folder name.

    See: https://cloudinary.com/documentation/admin_api#get_the_details_of_a_single_upload_mapping

    :param name: The folder name.
    :type name: str
    :param options: Additional options (none currently recognized).
    :return: Details of the specified upload mapping.
    :rtype: Response
    r  folderr   rF   r   r   s       r   upload_mappingr    s6     
CFV77w777r   c                 F    dg}t          |           }t          d||fi |S )a>  
    Deletes an upload mapping by folder name.

    See: https://cloudinary.com/documentation/admin_api#delete_an_upload_mapping

    :param name: The folder name.
    :type name: str
    :param options: Additional options (none currently recognized).
    :return: The result of the deletion.
    :rtype: Response
    r  r  r   r  r   s       r   delete_upload_mappingr    s6     
CF3::':::r   c                     dg}t          |           }|                    t          |d                     t          d||fi |S )a|  
    Updates an upload mapping by folder name.

    See: https://cloudinary.com/documentation/admin_api#update_an_upload_mapping

    :param name: The folder name.
    :type name: str
    :param options: Additional parameters to update.
    :keyword str template: A URL template for the given folder name.
    :return: The result of the update operation.
    :rtype: Response
    r  r  templater   rF   r4   r&   r   r   s       r   update_upload_mappingr    sR     
CF
MM$w
++,,,V77w777r   c                     dg}t          |           }|                    t          |d                     t          d||fi |S )a^  
    Creates a new upload mapping.

    See: https://cloudinary.com/documentation/admin_api#create_an_upload_mapping

    :param name: The folder name.
    :type name: str
    :param options: Additional parameters.
    :keyword str template: A URL template for the given folder name.
    :return: The result of the creation.
    :rtype: Response
    r  r  r  rk   r  r   s       r   create_upload_mappingr    sR     
CF
MM$w
++,,,f88888r   c                  &    dg}t          d|i fi | S )a'  
    Lists all custom and built-in streaming profiles.

    See: https://cloudinary.com/documentation/admin_api#get_adaptive_streaming_profiles

    :param options: Additional optional parameters (none currently recognized).
    :return: The list of streaming profiles.
    :rtype: Response
    streaming_profilesGETr   r   s     r   list_streaming_profilesr#    s&      
 CR337333r   c                 (    d| g}t          d|i fi |S )a  
    Retrieves details of a specific streaming profile by name.

    See: https://cloudinary.com/documentation/admin_api#get_details_of_a_single_streaming_profile

    :param name: The name of the streaming profile.
    :type name: str
    :param options: Additional optional parameters (none currently recognized).
    :return: The details of the streaming profile.
    :rtype: Response
    r!  r"  r   r   s      r   get_streaming_profiler%    s(      
&CR337333r   c                 (    d| g}t          d|i fi |S )a  
    Deletes a specific streaming profile by name (or reverts a built-in).

    See: https://cloudinary.com/documentation/admin_api#delete_or_revert_the_specified_streaming_profile

    :param name: The name of the streaming profile to delete.
    :type name: str
    :param options: Additional optional parameters (none currently recognized).
    :return: The result of the deletion.
    :rtype: Response
    r!  DELETEr   r   s      r   delete_streaming_profiler(    s(      
&C366g666r   c                 H    dg}t          di |}| |d<   t          d||fi |S )a  
    Creates a new custom streaming profile.

    See: https://cloudinary.com/documentation/admin_api#create_a_streaming_profile

    :param name: The name for the new streaming profile.
    :type name: str
    :param options: Additional options.
    :keyword str display_name: A display name for the streaming profile.
    :keyword list representations: A list of transformations (dict or str).
    :return: The created streaming profile.
    :rtype: Response
    r!  r   POSTr2   "__prepare_streaming_profile_paramsr   r   s       r   create_streaming_profiler-    sB      
 C/::'::FF6Nf88888r   c                 @    d| g}t          di |}t          d||fi |S )a  
    Updates an existing streaming profile.

    See: https://cloudinary.com/documentation/admin_api#update_an_existing_streaming_profile

    :param name: The name of the streaming profile to update.
    :type name: str
    :param options: Additional options.
    :keyword str display_name: A display name for the streaming profile.
    :keyword list representations: A list of transformations (dict or str).
    :return: The updated streaming profile.
    :rtype: Response
    r!  PUTr2   r+  r   s       r   update_streaming_profiler0    s;      
&C/::'::FV77w777r   c                        fd|D             S )a@  
    Returns a dictionary containing only the specified keys from the source.

    :param source: The source dictionary.
    :type source: dict
    :param keys: The keys to retain.
    :type keys: list or tuple of str or str
    :return: A new dictionary with only the specified keys.
    :rtype: dict
    :internal
    c                 *    i | ]}|v ||         S r2   r2   ).0rV   sources     r   
<dictcomp>zonly.<locals>.<dictcomp>:  s$    >>>vCr   r2   )r4  keyss   ` r   r&   r&   .  s     ?>>>>>>>r   c                 h    t          | t                    r| S t          j        j        di | d         S )z
    Converts a transformation (dict or str) into the correct string format.

    :param transformation: The transformation to convert.
    :type transformation: dict or str
    :return: The transformation as a string.
    :rtype: str
    :internal
    r   Nr2   )r   r   
cloudinaryr   generate_transformation_stringr   s    r   r   r   =  s=     .,// T>PPPPQRSSr   c                      t          | d          }d| v r)d | d         D             }t          j        |          |d<   |S )a  
    Prepares the parameters for creating or updating a streaming profile.

    :param options: Additional options, typically including "representations" and "display_name".
    :return: A dictionary of parameters for the streaming profile API call.
    :rtype: dict
    :internal
    r   representationsc                 0    g | ]}d t          |          iS r:  )r   )r3  transs     r   
<listcomp>z6__prepare_streaming_profile_params.<locals>.<listcomp>X  s<     D D D$ -.CE.J.JK D D Dr   )r&   jsondumps)r   r(   r<  s      r   r,  r,  M  sa     '>**FG##D D(/0A(BD D D$(J$?$? !Mr   c           
          t          ddt          j        |                     d                    it	          | ddd          }|                    |           |S )aq  
    Prepares parameters for delete resource methods, including transformations, keep_original,
    next_cursor, invalidate, etc.

    :param options: A dict of delete-related options.
    :param params: Additional parameters (e.g., prefix, public_ids, asset_ids).
    :type params: dict
    :return: A combined dictionary of params.
    :rtype: dict
    :internal
    r   r   r`   r   r2   )rF   r   r   r   r&   r4   )r   r(   ps      r   r   r   ^  si     	 	L 	LU.w{{;L/M/MNN 	LG_m\JJ	L 	LAHHVHr   c                       t          dg i fi | S )a  
    Returns a list of all metadata field definitions.

    See: https://cloudinary.com/documentation/admin_api#get_metadata_fields

    :param options: Additional optional parameters (none currently recognized).
    :return: A list of metadata fields.
    :rtype: Response
    r   r   r   s    r   list_metadata_fieldsrF  p  s     UB66g666r   c                 &    | g}t          d|i fi |S )a  
    Gets a metadata field by external id.

    See: https://cloudinary.com/documentation/admin_api#get_a_metadata_field_by_external_id

    :param field_external_id: The ID of the metadata field to retrieve.
    :type field_external_id: str
    :param options: Additional optional parameters (none currently recognized).
    :return: The metadata field details.
    :rtype: Response
    r   rE  field_external_idr   r!   s      r   metadata_field_by_field_idrJ  }  s&     
CUC77w777r   c                 :    t          dg t          |           fi |S )aL  
    Creates a new metadata field definition.

    See: https://cloudinary.com/documentation/admin_api#create_a_metadata_field

    :param field: The field to add.
    :type field: dict
    :param options: Additional optional parameters (none currently recognized).
    :return: The created metadata field.
    :rtype: Response
    rk   r   __metadata_field_params)fieldr   s     r   add_metadata_fieldrO    s'     VR)@)G)GSS7SSSr   c                 @    | g}t          d|t          |          fi |S )a  
    Updates a metadata field by external id.

    See: https://cloudinary.com/documentation/admin_api#update_a_metadata_field_by_external_id

    :param field_external_id: The ID of the metadata field to update.
    :type field_external_id: str
    :param field: The field definition to update.
    :type field: dict
    :param options: Additional optional parameters (none currently recognized).
    :return: The updated metadata field.
    :rtype: Response
    r   rL  )rI  rN  r   r!   s       r   update_metadata_fieldrQ    s/     
CUC)@)G)GSS7SSSr   c                 4    t          | ddddddddd	d
          S )z
    Builds the parameters needed for creating or updating a metadata field.

    :param field: The field definition.
    :type field: dict
    :return: The relevant key-value pairs.
    :rtype: dict
    :internal
    r/   external_idlabel	mandatoryrestrictionsdefault_valuedefault_disabled
validation
datasourceallow_dynamic_list_valuesr   )rN  s    r   rM  rM    s2     v}g{N!3\<Qln n nr   c                 &    | g}t          d|i fi |S )a  
    Deletes a metadata field definition.

    See: https://cloudinary.com/documentation/admin_api#delete_a_metadata_field_by_external_id

    :param field_external_id: The external ID of the field to delete.
    :type field_external_id: str
    :param options: Additional optional parameters (none currently recognized).
    :return: An array with a "message" key. "ok" value indicates a successful deletion.
    :rtype: Response
    r   rE  rH  s      r   delete_metadata_fieldr]    s&     
CXsB::':::r   c                 0    | dg}d|i}t          d||fi |S )a.  
    Deletes entries in a metadata field datasource.

    See: https://cloudinary.com/documentation/admin_api#delete_entries_in_a_metadata_field_datasource

    :param field_external_id: The ID of the field to update.
    :type field_external_id: str
    :param entries_external_id: The IDs of the entries to delete from the datasource.
    :type entries_external_id: list[str]
    :param options: Additional optional parameters (none currently recognized).
    :return: A response indicating the success or failure of the deletion.
    :rtype: Response
    rZ  external_idsr   rE  )rI  entries_external_idr   r!   r(   s        r   delete_datasource_entriesra    s3     l
+C12FXsF>>g>>>r   c                     g }|D ]*}t          |dd          }|r|                    |           +| dg}d|i}t          d||fi |S )a  
    Updates a metadata field datasource.

    See: https://cloudinary.com/documentation/admin_api#update_a_metadata_field_datasource

    :param field_external_id: The external ID of the field to update.
    :type field_external_id: str
    :param entries_external_id: The list of entries to update/add.
    :type entries_external_id: list[dict]
    :param options: Additional optional parameters (none currently recognized).
    :return: The updated metadata field.
    :rtype: Response
    rS  rW   rZ  valuesr   )r&   r    r   )rI  r`  r   rc  itemexternalr!   r(   s           r    update_metadata_field_datasourcerf    sr     F# $ $mW55 	$MM(###l
+CFUC;;7;;;r   c                 0    | dg}d|i}t          d||fi |S )a@  
    Restores entries in a metadata field datasource.

    See: https://cloudinary.com/documentation/admin_api#restore_entries_in_a_metadata_field_datasource

    :param field_external_id: The ID of the metadata field.
    :type field_external_id: str
    :param entries_external_ids: An array of IDs of datasource entries to restore (unblock).
    :type entries_external_ids: list[str]
    :param options: Additional optional parameters (none currently recognized).
    :return: A response indicating the success or failure of the restore operation.
    :rtype: Response
    datasource_restorer_  rk   rE  )rI  entries_external_idsr   r!   r(   s        r   !restore_metadata_field_datasourcerj    s4     2
3C23FVS&<<G<<<r   c                 4    | ddg}||d}t          d||fi |S )am  
    Reorders a metadata field datasource. Currently supports ordering by 'value'.

    See: https://cloudinary.com/documentation/admin_api#order_a_metadata_field_datasource

    :param field_external_id: The ID of the metadata field.
    :type field_external_id: str
    :param order_by: Criteria for the order. Currently, supports only 'value'.
    :type order_by: str
    :param direction: Optional direction: 'asc' or 'desc'.
    :type direction: str, optional
    :param options: Additional optional parameters (none currently recognized).
    :return: The result of the ordering operation.
    :rtype: Response
    rZ  orderorder_byrb   rk   rE  )rI  rn  rb   r   r!   r(   s         r   !reorder_metadata_field_datasourcero    s7      lG
4C";;FVS&<<G<<<r   c                 0    dg}| |d}t          d||fi |S )a  
    Reorders metadata fields.

    :param order_by: Criteria for the order (one of 'label', 'external_id', 'created_at').
    :type order_by: str
    :param direction: Optional direction: 'asc' or 'desc'.
    :type direction: str, optional
    :param options: Additional optional parameters (none currently recognized).
    :return: The result of the ordering operation.
    :rtype: Response
    rl  rm  r   rE  )rn  rb   r   r!   r(   s        r   reorder_metadata_fieldsrq     s2     )C";;FUC;;7;;;r   c                       t          dg i fi | S )a  
    Returns a list of all metadata rules definitions.

    See: https://cloudinary.com/documentation/admin_api#get_metadata_rules

    :param options: Additional optional parameters (none currently recognized).
    :return: A list of metadata rules.
    :rtype: Response
    r   r   r   s    r   list_metadata_rulesrt  1  s     #5"b<<G<<<r   c           	      ,    t          | dddddd          S )z
    Builds the parameters needed for creating or updating a metadata rule.

    :param rule: The rule definition.
    :type rule: dict
    :return: The relevant key-value pairs.
    :rtype: dict
    :internal
    rS  metadata_field_id	conditionresultr   stater   )rules    r   __metadata_rule_paramsr{  =  s!     m%8+xQWY`aaar   c                 :    t          dg t          |           fi |S )aF  
    Creates a new metadata rule definition.

    See: https://cloudinary.com/documentation/admin_api#create_a_metadata_rule

    :param rule: The rule to add.
    :type rule: dict
    :param options: Additional optional parameters (none currently recognized).
    :return: The created metadata rule.
    :rtype: Response
    rk   r   r{  )rz  r   s     r   add_metadata_ruler~  J  s'     #62/Ed/K/KWWwWWWr   c                 @    | g}t          d|t          |          fi |S )a  
    Updates a metadata rule by external id.

    See: https://cloudinary.com/documentation/admin_api#update_a_metadata_rule_by_id

    :param rule_external_id: The ID of the metadata rule to update.
    :type rule_external_id: str
    :param rule: The rule definition to update.
    :type rule: dict
    :param options: Additional optional parameters (none currently recognized).
    :return: The updated metadata rule.
    :rtype: Response
    r   r}  )rule_external_idrz  r   r!   s       r   update_metadata_ruler  X  s/     
C"5#/Ed/K/KWWwWWWr   c                 &    | g}t          d|i fi |S )a  
    Deletes a metadata rule definition.

    See: https://cloudinary.com/documentation/admin_api#delete_a_metadata_rule_by_id

    :param rule_external_id: The external ID of the rule to delete.
    :type rule_external_id: str
    :param options: Additional optional parameters (none currently recognized).
    :return: An array with a "success" key. true value indicates a successful deletion.
    :rtype: Response
    r   rs  )r  r   r!   s      r   delete_metadata_ruler  i  s&     
C"8S"@@@@@r   c                 \    dd| g}|||                     d          d}t          d||fi |S )a  
    Analyzes an asset with the requested analysis type.

    :param input_type: The type of input for the asset to analyze (e.g. 'uri').
    :type input_type: str
    :param analysis_type: The type of analysis to run (e.g. 'google_tagging', 'captioning', 'fashion').
    :type analysis_type: str
    :param uri: The URI of the asset to analyze.
    :type uri: str, optional
    :param options: Additional optional parameters (none currently recognized).
    :return: The analysis result.
    :rtype: Response
    analysisanalyze
parameters)analysis_typer!   r  rk   )r   r	   )
input_typer  r!   r   api_urir(   s         r   r  r  y  sM     9j1G&kk,// F
 ;;7;;;r   )N)NNNN)r.   rC   N)r.   rC   )fr   r@  sixr   r8  r   cloudinary.api_client.call_apir   r   r   r   r	   cloudinary.exceptionsr
   r   r   r   r   r   r   r   r   r$   r+   r*   r<   rA   rI   rM   rS   rX   rG   r3   re   rq   rt   rn   r4   r   r   r   r   r   r   r   r   r   r   r   r   r8   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r	  r  r  r  r  r  r  r  r  r#  r%  r(  r-  r0  r&   r   r,  r   rF  rJ  rO  rQ  rM  r]  ra  rf  rj  ro  rq  rt  r{  r~  r  r  r  r2   r   r   <module>r     s-                                                  9 9 94 4 44? ? ?"
> 
> 
>8 8 868 8 808 8 828 8 808 8 8*8 8 8*8 8 8 88     4 4 4 4:"8 "8 "8J8 8 8BX X XC9 C9 C9L; ; ;6; ; ;*; ; ;2; ; ;4; ; ;.; ; ;$ W[ ;  ;  ;  ;F; ; ;&9 9 9 9.9 9 9&; ; ; ;.; ; ;&g g g&8 8 8$8 8 8(; ; ;"9 9 929 9 9&9 9 9(9 9 9(9 9 9(] ] ] N N N"7 7 7 8 8 8,9 9 9*e e eu u u"C C CK K K$I I I&9 9 9,9 9 9$] ] ] 8 8 8"; ; ;"8 8 8&9 9 9&4 4 44 4 4 7 7 7 9 9 9(8 8 8&? ? ?T T T   "  $
7 
7 
78 8 8 T T TT T T$n n n; ; ; ? ? ?&< < <2= = =&= = = =*< < < <"
= 
= 
=
b 
b 
bX X XX X X"A A A < < < < < <r   