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

hub.exec.boto3.client.opsworks.assign_volume
hub.exec.boto3.client.opsworks.deregister_volume
hub.exec.boto3.client.opsworks.describe_volumes
hub.exec.boto3.client.opsworks.register_volume
hub.exec.boto3.client.opsworks.unassign_volume
hub.exec.boto3.client.opsworks.update_volume
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, volume_id: Text, instance_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Assigns one of the stack's registered Amazon EBS volumes to a specified instance. The volume must first be
    registered with the stack by calling RegisterVolume. After you register the volume, you must call UpdateVolume
    to specify a mount point before calling AssignVolume. For more information, see Resource Management.  Required
    Permissions: To use this action, an IAM user must have a Manage permissions level for the stack, or an attached
    policy that explicitly grants permissions. For more information on user permissions, see Managing User
    Permissions.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        volume_id(Text): The volume ID.
        instance_id(Text, optional): The instance ID. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.opsworks.assign_volume(
                ctx,
                
                
                **{"VolumeId": volume_id, "InstanceId": instance_id}
            )
            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.opsworks.describe_volumes(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, volume_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Unassigns an assigned Amazon EBS volume. The volume remains registered with the stack. For more information, see
    Resource Management.  Required Permissions: To use this action, an IAM user must have a Manage permissions level
    for the stack, or an attached policy that explicitly grants permissions. For more information on user
    permissions, see Managing User Permissions.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        volume_id(Text): The volume ID.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.opsworks.unassign_volume(
                ctx,
                
                
                **{"VolumeId": volume_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.opsworks.describe_volumes(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

