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

hub.exec.boto3.client.customer_profiles.delete_profile_object
hub.exec.boto3.client.customer_profiles.list_profile_objects
hub.exec.boto3.client.customer_profiles.put_profile_object
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, object_type_name: Text, object_: Text, domain_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Adds additional objects to customer profiles of a given ObjectType. When adding a specific profile object, like
    a Contact Trace Record (CTR), an inferred profile can get created if it is not mapped to an existing profile.
    The resulting profile will only have a phone number populated in the standard ProfileObject. Any additional CTRs
    with the same phone number will be mapped to the same inferred profile. When a ProfileObject is created and if a
    ProfileObjectType already exists for the ProfileObject, it will provide data to a standard profile depending on
    the ProfileObjectType definition. PutProfileObject needs an ObjectType, which can be created using
    PutProfileObjectType.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        object_type_name(Text): The name of the profile object type.
        object_(Text): A string that is serialized from a JSON object.
        domain_name(Text): The unique name of the domain.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.customer_profiles.profile_object.present:
                - name: value
                - object_type_name: value
                - object_: value
                - domain_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.customer_profiles.profile_object.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.customer_profiles.list_profile_objects(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.customer_profiles.put_profile_object(
                ctx,
                
                
                **{"ObjectTypeName": object_type_name, "Object": object_, "DomainName": domain_name}
            )
            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.customer_profiles.list_profile_objects(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, profile_id: Text, profile_object_unique_key: Text, object_type_name: Text, domain_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes an object associated with a profile of a given ProfileObjectType.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        profile_id(Text): The unique identifier of a customer profile.
        profile_object_unique_key(Text): The unique identifier of the profile object generated by the service.
        object_type_name(Text): The name of the profile object type.
        domain_name(Text): The unique name of the domain.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.customer_profiles.profile_object.absent:
                - name: value
                - profile_id: value
                - profile_object_unique_key: value
                - object_type_name: value
                - domain_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.customer_profiles.profile_object.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.customer_profiles.list_profile_objects(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.customer_profiles.delete_profile_object(
                ctx,
                
                
                **{"ProfileId": profile_id, "ProfileObjectUniqueKey": profile_object_unique_key, "ObjectTypeName": object_type_name, "DomainName": domain_name}
            )
            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.customer_profiles.list_profile_objects(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

