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

hub.exec.boto3.client.connect.associate_lex_bot
hub.exec.boto3.client.connect.disassociate_lex_bot
hub.exec.boto3.client.connect.list_lex_bots
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, instance_id: Text, lex_bot: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    This API is in preview release for Amazon Connect and is subject to change. Allows the specified Amazon Connect
    instance to access the specified Amazon Lex bot.

    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.
        lex_bot(Dict): The Amazon Lex bot to associate with the instance.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, instance_id: Text, bot_name: Text, lex_region: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    This API is in preview release for Amazon Connect and is subject to change. Revokes authorization from the
    specified instance to access the specified Amazon Lex bot.

    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.
        bot_name(Text): The name of the Amazon Lex bot. Maximum character limit of 50.
        lex_region(Text): The Region in which the Amazon Lex bot has been created.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.connect.disassociate_lex_bot(
                ctx,
                
                
                **{"InstanceId": instance_id, "BotName": bot_name, "LexRegion": lex_region}
            )
            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.list_lex_bots(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

