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

hub.exec.boto3.client.lexv2_runtime.delete_session
hub.exec.boto3.client.lexv2_runtime.get_session
hub.exec.boto3.client.lexv2_runtime.put_session
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, bot_id: Text, bot_alias_id: Text, locale_id: Text, session_id: Text, session_state: Dict, messages: List = None, request_attributes: Dict = None, response_content_type: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new session or modifies an existing session with an Amazon Lex V2 bot. Use this operation to enable
    your application to set the state of the bot.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        bot_id(Text): The identifier of the bot that receives the session data.
        bot_alias_id(Text): The alias identifier of the bot that receives the session data.
        locale_id(Text): The locale where the session is in use.
        session_id(Text): The identifier of the session that receives the session data.
        messages(List, optional): A list of messages to send to the user. Messages are sent in the order that they are defined in
            the list. Defaults to None.
        session_state(Dict): Sets the state of the session with the user. You can use this to set the current intent,
            attributes, context, and dialog action. Use the dialog action to determine the next step that
            Amazon Lex V2 should use in the conversation with the user.
        request_attributes(Dict, optional): Request-specific information passed between Amazon Lex V2 and the client application. The
            namespace x-amz-lex: is reserved for special attributes. Don't create any request attributes
            with the prefix x-amz-lex:. Defaults to None.
        response_content_type(Text, optional): The message that Amazon Lex V2 returns in the response can be either text or speech depending on
            the value of this parameter.    If the value is text/plain; charset=utf-8, Amazon Lex V2 returns
            text in the response. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.lexv2_runtime.session.present:
                - name: value
                - bot_id: value
                - bot_alias_id: value
                - locale_id: value
                - session_id: value
                - session_state: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.lexv2_runtime.session.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.lexv2_runtime.get_session(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.lexv2_runtime.put_session(
                ctx,
                
                
                **{"botId": bot_id, "botAliasId": bot_alias_id, "localeId": locale_id, "sessionId": session_id, "messages": messages, "sessionState": session_state, "requestAttributes": request_attributes, "responseContentType": response_content_type}
            )
            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.lexv2_runtime.get_session(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, bot_id: Text, bot_alias_id: Text, locale_id: Text, session_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes session information for a specified bot, alias, and user ID.  You can use this operation to restart a
    conversation with a bot. When you remove a session, the entire history of the session is removed so that you can
    start again. You don't need to delete a session. Sessions have a time limit and will expire. Set the session
    time limit when you create the bot. The default is 5 minutes, but you can specify anything between 1 minute and
    24 hours. If you specify a bot or alias ID that doesn't exist, you receive a BadRequestException.  If the locale
    doesn't exist in the bot, or if the locale hasn't been enables for the alias, you receive a BadRequestException.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        bot_id(Text): The identifier of the bot that contains the session data.
        bot_alias_id(Text): The alias identifier in use for the bot that contains the session data.
        locale_id(Text): The locale where the session is in use.
        session_id(Text): The identifier of the session to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.lexv2_runtime.session.absent:
                - name: value
                - bot_id: value
                - bot_alias_id: value
                - locale_id: value
                - session_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.lexv2_runtime.session.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.lexv2_runtime.get_session(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.lexv2_runtime.delete_session(
                ctx,
                
                
                **{"botId": bot_id, "botAliasId": bot_alias_id, "localeId": locale_id, "sessionId": session_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.lexv2_runtime.get_session(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

