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

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



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, contact_list_name: Text, email_address: Text, topic_preferences: List = None, unsubscribe_all: bool = None, attributes_data: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a contact, which is an end-user who is receiving the email, and adds them to a contact list.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        contact_list_name(Text): The name of the contact list to which the contact should be added.
        email_address(Text): The contact's email address.
        topic_preferences(List, optional): The contact's preferences for being opted-in to or opted-out of topics. Defaults to None.
        unsubscribe_all(bool, optional): A boolean value status noting if the contact is unsubscribed from all contact list topics. Defaults to None.
        attributes_data(Text, optional): The attribute data attached to a contact. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.sesv2.create_contact(
                ctx,
                
                
                **{"ContactListName": contact_list_name, "EmailAddress": email_address, "TopicPreferences": topic_preferences, "UnsubscribeAll": unsubscribe_all, "AttributesData": attributes_data}
            )
            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.sesv2.get_contact(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, contact_list_name: Text, email_address: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes a contact from a contact list.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        contact_list_name(Text): The name of the contact list from which the contact should be removed.
        email_address(Text): The contact's email address.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

