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

hub.exec.boto3.client.ssm_contacts.activate_contact_channel
hub.exec.boto3.client.ssm_contacts.create_contact_channel
hub.exec.boto3.client.ssm_contacts.deactivate_contact_channel
hub.exec.boto3.client.ssm_contacts.delete_contact_channel
hub.exec.boto3.client.ssm_contacts.get_contact_channel
hub.exec.boto3.client.ssm_contacts.list_contact_channels
hub.exec.boto3.client.ssm_contacts.update_contact_channel
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, contact_id: Text, type_: Text, delivery_address: Dict, defer_activation: bool = None, idempotency_token: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    A contact channel is the method that Incident Manager uses to engage your contact.

    Args:
        name(Text): The name of the contact channel.
        contact_id(Text): The Amazon Resource Name (ARN) of the contact you are adding the contact channel to.
        type_(Text): Incident Manager supports three types of contact channels:    SMS     VOICE     EMAIL.
        delivery_address(Dict): The details that Incident Manager uses when trying to engage the contact channel. The format is
            dependent on the type of the contact channel. The following are the expected formats:   SMS -
            '+' followed by the country code and phone number   VOICE - '+' followed by the country code and
            phone number   EMAIL - any standard email format.
        defer_activation(bool, optional): If you want to activate the channel at a later time, you can choose to defer activation.
            Incident Manager can't engage your contact channel until it has been activated. Defaults to None.
        idempotency_token(Text, optional): A token ensuring that the action is called only once with the specified details. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.ssm_contacts.contact_channel.present:
                - name: value
                - contact_id: value
                - type_: value
                - delivery_address: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ssm_contacts.contact_channel.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.ssm_contacts.get_contact_channel(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ssm_contacts.create_contact_channel(
                ctx,
                
                
                **{"Name": name, "ContactId": contact_id, "Type": type_, "DeliveryAddress": delivery_address, "DeferActivation": defer_activation, "IdempotencyToken": idempotency_token}
            )
            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.ssm_contacts.get_contact_channel(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, contact_channel_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    To no longer receive engagements on a contact channel, you can delete the channel from a contact. Deleting the
    contact channel removes it from the contact's engagement plan. If you delete the only contact channel for a
    contact, you won't be able to engage that contact during an incident.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        contact_channel_id(Text): The Amazon Resource Name (ARN) of the contact channel.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

