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

hub.exec.boto3.client.ssm_contacts.create_contact
hub.exec.boto3.client.ssm_contacts.delete_contact
hub.exec.boto3.client.ssm_contacts.get_contact
hub.exec.boto3.client.ssm_contacts.list_contacts
hub.exec.boto3.client.ssm_contacts.update_contact
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, alias: Text, type_: Text, plan: Dict, display_name: Text = None, tags: List = None, idempotency_token: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Contacts are either the contacts that Incident Manager engages during an incident or the escalation plans that
    Incident Manager uses to engage contacts in phases during an incident.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        alias(Text): The short name to quickly identify a contact or escalation plan. The contact alias must be
            unique and identifiable.
        display_name(Text, optional): The full name of the contact or escalation plan. Defaults to None.
        type_(Text): To create an escalation plan use ESCALATION. To create a contact use PERSONAL.
        plan(Dict): A list of stages. A contact has an engagement plan with stages that contact specified contact
            channels. An escalation plan uses stages that contact specified contacts.
        tags(List, optional): Adds a tag to the target. You can only tag resources created in the first Region of your
            replication set. 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.present:
                - name: value
                - alias: value
                - type_: value
                - plan: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ssm_contacts.contact.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(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ssm_contacts.create_contact(
                ctx,
                
                
                **{"Alias": alias, "DisplayName": display_name, "Type": type_, "Plan": plan, "Tags": tags, "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(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, contact_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    To remove a contact from Incident Manager, you can delete the contact. Deleting a contact removes them from all
    escalation plans and related response plans. Deleting an escalation plan removes it from all related response
    plans. You will have to recreate the contact and its contact channels before you can use it again.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        contact_id(Text): The Amazon Resource Name (ARN) of the contact that you're deleting.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

