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

hub.exec.boto3.client.pinpoint.create_push_template
hub.exec.boto3.client.pinpoint.delete_push_template
hub.exec.boto3.client.pinpoint.get_push_template
hub.exec.boto3.client.pinpoint.update_push_template
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, push_notification_template_request: Dict, template_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a message template for messages that are sent through a push notification channel.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        push_notification_template_request(Dict): Specifies the content and settings for a message template that can be used in messages that are
            sent through a push notification channel.
        template_name(Text): The name of the message template. A template name must start with an alphanumeric character and
            can contain a maximum of 128 characters. The characters can be alphanumeric characters,
            underscores (_), or hyphens (-). Template names are case sensitive.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.pinpoint.create_push_template(
                ctx,
                
                
                **{"PushNotificationTemplateRequest": push_notification_template_request, "TemplateName": template_name}
            )
            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.pinpoint.get_push_template(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, template_name: Text, version: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a message template for messages that were sent through a push notification channel.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        template_name(Text): The name of the message template. A template name must start with an alphanumeric character and
            can contain a maximum of 128 characters. The characters can be alphanumeric characters,
            underscores (_), or hyphens (-). Template names are case sensitive.
        version(Text, optional): The unique identifier for the version of the message template to update, retrieve information
            about, or delete. To retrieve identifiers and other information for all the versions of a
            template, use the Template Versions resource. If specified, this value must match the identifier
            for an existing template version. If specified for an update operation, this value must match
            the identifier for the latest existing version of the template. This restriction helps ensure
            that race conditions don't occur. If you don't specify a value for this parameter, Amazon
            Pinpoint does the following: For a get operation, retrieves information about the active version
            of the template. For an update operation, saves the updates to (overwrites) the latest existing
            version of the template, if the create-new-version parameter isn't used or is set to false. For
            a delete operation, deletes the template, including all versions of the template. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

