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

hub.exec.boto3.client.alexaforbusiness.create_contact
hub.exec.boto3.client.alexaforbusiness.delete_contact
hub.exec.boto3.client.alexaforbusiness.get_contact
hub.exec.boto3.client.alexaforbusiness.search_contacts
hub.exec.boto3.client.alexaforbusiness.update_contact
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, first_name: Text, display_name: Text = None, last_name: Text = None, phone_number: Text = None, phone_numbers: List = None, sip_addresses: List = None, client_request_token: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a contact with the specified details.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        display_name(Text, optional): The name of the contact to display on the console. Defaults to None.
        first_name(Text): The first name of the contact that is used to call the contact on the device.
        last_name(Text, optional): The last name of the contact that is used to call the contact on the device. Defaults to None.
        phone_number(Text, optional): The phone number of the contact in E.164 format. The phone number type defaults to WORK. You can
            specify PhoneNumber or PhoneNumbers. We recommend that you use PhoneNumbers, which lets you
            specify the phone number type and multiple numbers. Defaults to None.
        phone_numbers(List, optional): The list of phone numbers for the contact. Defaults to None.
        sip_addresses(List, optional): The list of SIP addresses for the contact. Defaults to None.
        client_request_token(Text, optional): A unique, user-specified identifier for this request that ensures idempotency. Defaults to None.
        tags(List, optional): The tags to be added to the specified resource. Do not provide system tags. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.alexaforbusiness.contact.present:
                - name: value
                - first_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.alexaforbusiness.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.alexaforbusiness.get_contact(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.alexaforbusiness.create_contact(
                ctx,
                
                
                **{"DisplayName": display_name, "FirstName": first_name, "LastName": last_name, "PhoneNumber": phone_number, "PhoneNumbers": phone_numbers, "SipAddresses": sip_addresses, "ClientRequestToken": client_request_token, "Tags": tags}
            )
            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.alexaforbusiness.get_contact(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, contact_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a contact by the contact ARN.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        contact_arn(Text): The ARN of the contact to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

