"""
Autogenerated state module using `pop-create-idem <https://gitlab.com/saltstack/pop/pop-create-idem>`__

hub.exec.boto3.client.rekognition.create_collection
hub.exec.boto3.client.rekognition.delete_collection
hub.exec.boto3.client.rekognition.describe_collection
hub.exec.boto3.client.rekognition.list_collections
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, collection_id: Text, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a collection in an AWS Region. You can add faces to the collection using the IndexFaces operation.  For
    example, you might create collections, one for each of your application users. A user can then index faces using
    the IndexFaces operation and persist results in a specific collection. Then, a user can search the collection
    for faces in the user-specific container.  When you create a collection, it is associated with the latest
    version of the face model version.  Collection names are case-sensitive.  This operation requires permissions to
    perform the rekognition:CreateCollection action. If you want to tag your collection, you also require permission
    to perform the rekognition:TagResource operation.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        collection_id(Text): ID for the collection that you are creating.
        tags(Dict, optional):  A set of tags (key-value pairs) that you want to attach to the collection. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.rekognition.collection.present:
                - name: value
                - collection_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.rekognition.collection.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    
    before = await hub.exec.boto3.client.rekognition.describe_collection(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.rekognition.create_collection(
                ctx,
                
                
                **{"CollectionId": collection_id, "Tags": tags}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            ret["comment"] = f"Created '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    
    # TODO perform other modifications as needed here
    ...

    after = await hub.exec.boto3.client.rekognition.describe_collection(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, collection_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified collection. Note that this operation removes all faces in the collection. For an example,
    see delete-collection-procedure. This operation requires permissions to perform the rekognition:DeleteCollection
    action.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        collection_id(Text): ID of the collection to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.rekognition.collection.absent:
                - name: value
                - collection_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.rekognition.collection.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    

    before = await hub.exec.boto3.client.rekognition.describe_collection(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.rekognition.delete_collection(
                ctx,
                
                
                **{"CollectionId": collection_id}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            result["comment"] = f"Deleted '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    

    after = await hub.exec.boto3.client.rekognition.describe_collection(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

