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

hub.exec.boto3.client.lightsail.create_contact_method
hub.exec.boto3.client.lightsail.delete_contact_method
hub.exec.boto3.client.lightsail.get_contact_methods
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, protocol: Text, contact_endpoint: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an email or SMS text message contact method. A contact method is used to send you notifications about
    your Amazon Lightsail resources. You can add one email address and one mobile phone number contact method in
    each AWS Region. However, SMS text messaging is not supported in some AWS Regions, and SMS text messages cannot
    be sent to some countries/regions. For more information, see Notifications in Amazon Lightsail.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        protocol(Text): The protocol of the contact method, such as Email or SMS (text messaging). The SMS protocol is
            supported only in the following AWS Regions.   US East (N. Virginia) (us-east-1)   US West
            (Oregon) (us-west-2)   Europe (Ireland) (eu-west-1)   Asia Pacific (Tokyo) (ap-northeast-1)
            Asia Pacific (Singapore) (ap-southeast-1)   Asia Pacific (Sydney) (ap-southeast-2)   For a list
            of countries/regions where SMS text messages can be sent, and the latest AWS Regions where SMS
            text messaging is supported, see Supported Regions and Countries in the Amazon SNS Developer
            Guide. For more information about notifications in Amazon Lightsail, see Notifications in Amazon
            Lightsail.
        contact_endpoint(Text): The destination of the contact method, such as an email address or a mobile phone number. Use
            the E.164 format when specifying a mobile phone number. E.164 is a standard for the phone number
            structure used for international telecommunication. Phone numbers that follow this format can
            have a maximum of 15 digits, and they are prefixed with the plus character (+) and the country
            code. For example, a U.S. phone number in E.164 format would be specified as +1XXX5550100. For
            more information, see E.164 on Wikipedia.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.lightsail.create_contact_method(
                ctx,
                
                
                **{"protocol": protocol, "contactEndpoint": contact_endpoint}
            )
            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.lightsail.get_contact_methods(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, protocol: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a contact method. A contact method is used to send you notifications about your Amazon Lightsail
    resources. You can add one email address and one mobile phone number contact method in each AWS Region. However,
    SMS text messaging is not supported in some AWS Regions, and SMS text messages cannot be sent to some
    countries/regions. For more information, see Notifications in Amazon Lightsail.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        protocol(Text): The protocol that will be deleted, such as Email or SMS (text messaging).  To delete an Email
            and an SMS contact method if you added both, you must run separate DeleteContactMethod actions
            to delete each protocol.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

