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

hub.exec.boto3.client.mgh.create_progress_update_stream
hub.exec.boto3.client.mgh.delete_progress_update_stream
hub.exec.boto3.client.mgh.list_progress_update_streams
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, progress_update_stream_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a progress update stream which is an AWS resource used for access control as well as a namespace for
    migration task names that is implicitly linked to your AWS account. It must uniquely identify the migration tool
    as it is used for all updates made by the tool; however, it does not need to be unique for each AWS account
    because it is scoped to the AWS account.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        progress_update_stream_name(Text): The name of the ProgressUpdateStream. Do not store personal data in this field.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.mgh.progress_update_stream.present:
                - name: value
                - progress_update_stream_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.mgh.progress_update_stream.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.mgh.list_progress_update_streams(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.mgh.create_progress_update_stream(
                ctx,
                DryRun=ctx.test,
                
                **{"ProgressUpdateStreamName": progress_update_stream_name}
            )
            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.mgh.list_progress_update_streams(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, progress_update_stream_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a progress update stream, including all of its tasks, which was previously created as an AWS resource
    used for access control. This API has the following traits:   The only parameter needed for
    DeleteProgressUpdateStream is the stream name (same as a CreateProgressUpdateStream call).   The call will
    return, and a background process will asynchronously delete the stream and all of its resources (tasks,
    associated resources, resource attributes, created artifacts).   If the stream takes time to be deleted, it
    might still show up on a ListProgressUpdateStreams call.    CreateProgressUpdateStream, ImportMigrationTask,
    NotifyMigrationTaskState, and all Associate[*] APIs related to the tasks belonging to the stream will throw
    "InvalidInputException" if the stream of the same name is in the process of being deleted.   Once the stream and
    all of its resources are deleted, CreateProgressUpdateStream for a stream of the same name will succeed, and
    that stream will be an entirely new logical resource (without any resources associated with the old stream).

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        progress_update_stream_name(Text): The name of the ProgressUpdateStream. Do not store personal data in this field.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.mgh.progress_update_stream.absent:
                - name: value
                - progress_update_stream_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.mgh.progress_update_stream.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.mgh.list_progress_update_streams(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.mgh.delete_progress_update_stream(
                ctx,
                DryRun=ctx.test,
                
                **{"ProgressUpdateStreamName": progress_update_stream_name}
            )
            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.mgh.list_progress_update_streams(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

