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

hub.exec.boto3.client.lex_models.create_intent_version
hub.exec.boto3.client.lex_models.delete_intent_version
hub.exec.boto3.client.lex_models.get_intent_versions
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, checksum: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new version of an intent based on the $LATEST version of the intent. If the $LATEST version of this
    intent hasn't changed since you last updated it, Amazon Lex doesn't create a new version. It returns the last
    version you created.  You can update only the $LATEST version of the intent. You can't update the numbered
    versions that you create with the CreateIntentVersion operation.   When you create a version of an intent,
    Amazon Lex sets the version to 1. Subsequent versions increment by 1. For more information, see versioning-
    intro.  This operation requires permissions to perform the lex:CreateIntentVersion action.

    Args:
        name(Text): The name of the intent that you want to create a new version of. The name is case sensitive.
        checksum(Text, optional): Checksum of the $LATEST version of the intent that should be used to create the new version. If
            you specify a checksum and the $LATEST version of the intent has a different checksum, Amazon
            Lex returns a PreconditionFailedException exception and doesn't publish a new version. If you
            don't specify a checksum, Amazon Lex publishes the $LATEST version. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.lex_models.create_intent_version(
                ctx,
                
                
                **{"Name": name, "checksum": checksum}
            )
            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.lex_models.get_intent_versions(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, version: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a specific version of an intent. To delete all versions of a intent, use the DeleteIntent operation.
    This operation requires permissions for the lex:DeleteIntentVersion action.

    Args:
        name(Text): The name of the intent.
        version(Text): The version of the intent to delete. You cannot delete the $LATEST version of the intent. To
            delete the $LATEST version, use the DeleteIntent operation.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

