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

hub.exec.boto3.client.connect.associate_instance_storage_config
hub.exec.boto3.client.connect.describe_instance_storage_config
hub.exec.boto3.client.connect.disassociate_instance_storage_config
hub.exec.boto3.client.connect.list_instance_storage_configs
hub.exec.boto3.client.connect.update_instance_storage_config
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, instance_id: Text, resource_type: Text, storage_config: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    This API is in preview release for Amazon Connect and is subject to change. Associates a storage resource type
    for the first time. You can only associate one type of storage configuration in a single call. This means, for
    example, that you can't define an instance with multiple S3 buckets for storing chat transcripts. This API does
    not create a resource that doesn't exist. It only associates it to the instance. Ensure that the resource being
    specified in the storage configuration, like an S3 bucket, exists when being used for association.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        instance_id(Text): The identifier of the Amazon Connect instance. You can find the instanceId in the ARN of the
            instance.
        resource_type(Text): A valid resource type.
        storage_config(Dict): A valid storage type.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.connect.instance_storage_config.present:
                - name: value
                - instance_id: value
                - resource_type: value
                - storage_config: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.connect.instance_storage_config.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.connect.describe_instance_storage_config(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.connect.associate_instance_storage_config(
                ctx,
                
                
                **{"InstanceId": instance_id, "ResourceType": resource_type, "StorageConfig": storage_config}
            )
            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.connect.describe_instance_storage_config(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, instance_id: Text, association_id: Text, resource_type: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    This API is in preview release for Amazon Connect and is subject to change. Removes the storage type
    configurations for the specified resource type and association ID.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        instance_id(Text): The identifier of the Amazon Connect instance. You can find the instanceId in the ARN of the
            instance.
        association_id(Text): The existing association identifier that uniquely identifies the resource type and storage
            config for the given instance ID.
        resource_type(Text): A valid resource type.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.connect.instance_storage_config.absent:
                - name: value
                - instance_id: value
                - association_id: value
                - resource_type: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.connect.instance_storage_config.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.connect.describe_instance_storage_config(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.connect.disassociate_instance_storage_config(
                ctx,
                
                
                **{"InstanceId": instance_id, "AssociationId": association_id, "ResourceType": resource_type}
            )
            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.connect.describe_instance_storage_config(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

