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

hub.exec.boto3.client.mgh.associate_discovered_resource
hub.exec.boto3.client.mgh.disassociate_discovered_resource
hub.exec.boto3.client.mgh.list_discovered_resources
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, progress_update_stream: Text, migration_task_name: Text, discovered_resource: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Associates a discovered resource ID from Application Discovery Service with a migration task.

    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): The identifier given to the MigrationTask. Do not store personal data in this field.
        discovered_resource(Dict): Object representing a Resource.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.mgh.associate_discovered_resource(
                ctx,
                DryRun=ctx.test,
                
                **{"ProgressUpdateStream": progress_update_stream, "MigrationTaskName": migration_task_name, "DiscoveredResource": discovered_resource}
            )
            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_discovered_resources(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, configuration_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Disassociate an Application Discovery Service discovered resource from a migration task.

    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): The identifier given to the MigrationTask. Do not store personal data in this field.
        configuration_id(Text): ConfigurationId of the Application Discovery Service resource to be disassociated.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

