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

hub.exec.boto3.client.sns.create_platform_application
hub.exec.boto3.client.sns.delete_platform_application
hub.exec.boto3.client.sns.list_platform_applications
resource = hub.tool.boto3.resource.create(ctx, "sns", "PlatformApplication", name)
hub.tool.boto3.resource.exec(resource, create_platform_endpoint, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, delete, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, set_attributes, *args, **kwargs)
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, platform: Text, attributes: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a platform application object for one of the supported push notification services, such as APNS and GCM
    (Firebase Cloud Messaging), to which devices and mobile apps may register. You must specify PlatformPrincipal
    and PlatformCredential attributes when using the CreatePlatformApplication action.  PlatformPrincipal and
    PlatformCredential are received from the notification service.   For ADM, PlatformPrincipal is client id and
    PlatformCredential is client secret.   For Baidu, PlatformPrincipal is API key and PlatformCredential is secret
    key.   For APNS and APNS_SANDBOX, PlatformPrincipal is SSL certificate and PlatformCredential is private key.
    For GCM (Firebase Cloud Messaging), there is no PlatformPrincipal and the PlatformCredential is API key.   For
    MPNS, PlatformPrincipal is TLS certificate and PlatformCredential is private key.   For WNS, PlatformPrincipal
    is Package Security Identifier and PlatformCredential is secret key.   You can use the returned
    PlatformApplicationArn as an attribute for the CreatePlatformEndpoint action.

    Args:
        name(Text): Application names must be made up of only uppercase and lowercase ASCII letters, numbers,
            underscores, hyphens, and periods, and must be between 1 and 256 characters long.
        platform(Text): The following platforms are supported: ADM (Amazon Device Messaging), APNS (Apple Push
            Notification Service), APNS_SANDBOX, and GCM (Firebase Cloud Messaging).
        attributes(Dict): For a list of attributes, see SetPlatformApplicationAttributes.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.sns.platform_application.present:
                - name: value
                - platform: value
                - attributes: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.sns.platform_application.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    resource = hub.tool.boto3.resource.create(ctx, "sns", "PlatformApplication", name)
    before = await hub.tool.boto3.resource.describe(resource)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.sns.create_platform_application(
                ctx,
                
                
                **{"Name": name, "Platform": platform, "Attributes": attributes}
            )
            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.tool.boto3.resource.describe(resource)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, platform_application_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a platform application object for one of the supported push notification services, such as APNS and GCM
    (Firebase Cloud Messaging). For more information, see Using Amazon SNS Mobile Push Notifications.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        platform_application_arn(Text): PlatformApplicationArn of platform application object to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.sns.platform_application.absent:
                - name: value
                - platform_application_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.sns.platform_application.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    resource = hub.tool.boto3.resource.create(ctx, "sns", "PlatformApplication", name)

    before = await hub.tool.boto3.resource.describe(resource)

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

