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

hub.exec.boto3.client.polly.delete_lexicon
hub.exec.boto3.client.polly.get_lexicon
hub.exec.boto3.client.polly.list_lexicons
hub.exec.boto3.client.polly.put_lexicon
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, content: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Stores a pronunciation lexicon in an AWS Region. If a lexicon with the same name already exists in the region,
    it is overwritten by the new lexicon. Lexicon operations have eventual consistency, therefore, it might take
    some time before the lexicon is available to the SynthesizeSpeech operation. For more information, see Managing
    Lexicons.

    Args:
        name(Text): Name of the lexicon. The name must follow the regular express format [0-9A-Za-z]{1,20}. That is,
            the name is a case-sensitive alphanumeric string up to 20 characters long.
        content(Text): Content of the PLS lexicon as string data.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified pronunciation lexicon stored in an AWS Region. A lexicon which has been deleted is not
    available for speech synthesis, nor is it possible to retrieve it using either the GetLexicon or ListLexicon
    APIs. For more information, see Managing Lexicons.

    Args:
        name(Text): The name of the lexicon to delete. Must be an existing lexicon in the region.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

