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

hub.exec.boto3.client.mgh.associate_created_artifact
hub.exec.boto3.client.mgh.disassociate_created_artifact
hub.exec.boto3.client.mgh.list_created_artifacts
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, progress_update_stream: Text, migration_task_name: Text, created_artifact: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Associates a created artifact of an AWS cloud resource, the target receiving the migration, with the migration
    task performed by a migration tool. This API has the following traits:   Migration tools can call the
    AssociateCreatedArtifact operation to indicate which AWS artifact is associated with a migration task.   The
    created artifact name must be provided in ARN (Amazon Resource Name) format which will contain information about
    type and region; for example: arn:aws:ec2:us-east-1:488216288981:image/ami-6d0ba87b.   Examples of the AWS
    resource behind the created artifact are, AMI's, EC2 instance, or DMS endpoint, etc.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        progress_update_stream(Text): The name of the ProgressUpdateStream.
        migration_task_name(Text): Unique identifier that references the migration task. Do not store personal data in this field.
        created_artifact(Dict): An ARN of the AWS resource related to the migration (e.g., AMI, EC2 instance, RDS instance,
            etc.).

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.mgh.associate_created_artifact(
                ctx,
                DryRun=ctx.test,
                
                **{"ProgressUpdateStream": progress_update_stream, "MigrationTaskName": migration_task_name, "CreatedArtifact": created_artifact}
            )
            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_created_artifacts(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, progress_update_stream: Text, migration_task_name: Text, created_artifact_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Disassociates a created artifact of an AWS resource with a migration task performed by a migration tool that was
    previously associated. This API has the following traits:   A migration user can call the
    DisassociateCreatedArtifacts operation to disassociate a created AWS Artifact from a migration task.   The
    created artifact name must be provided in ARN (Amazon Resource Name) format which will contain information about
    type and region; for example: arn:aws:ec2:us-east-1:488216288981:image/ami-6d0ba87b.   Examples of the AWS
    resource behind the created artifact are, AMI's, EC2 instance, or RDS instance, etc.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        progress_update_stream(Text): The name of the ProgressUpdateStream.
        migration_task_name(Text): Unique identifier that references the migration task to be disassociated with the artifact. Do
            not store personal data in this field.
        created_artifact_name(Text): An ARN of the AWS resource related to the migration (e.g., AMI, EC2 instance, RDS instance,
            etc.).

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.mgh.disassociate_created_artifact(
                ctx,
                DryRun=ctx.test,
                
                **{"ProgressUpdateStream": progress_update_stream, "MigrationTaskName": migration_task_name, "CreatedArtifactName": created_artifact_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_created_artifacts(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

