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

hub.exec.boto3.client.clouddirectory.create_facet
hub.exec.boto3.client.clouddirectory.delete_facet
hub.exec.boto3.client.clouddirectory.get_facet
hub.exec.boto3.client.clouddirectory.update_facet
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, schema_arn: Text, attributes: List = None, object_type: Text = None, facet_style: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new Facet in a schema. Facet creation is allowed only in development or applied schemas.

    Args:
        name(Text): The name of the Facet, which is unique for a given schema.
        schema_arn(Text): The schema ARN in which the new Facet will be created. For more information, see arns.
        attributes(List, optional): The attributes that are associated with the Facet. Defaults to None.
        object_type(Text, optional): Specifies whether a given object created from this facet is of type node, leaf node, policy or
            index.   Node: Can have multiple children but one parent.     Leaf node: Cannot have children
            but can have multiple parents.     Policy: Allows you to store a policy document and policy
            type. For more information, see Policies.     Index: Can be created with the Index API. Defaults to None.
        facet_style(Text, optional): There are two different styles that you can define on any given facet, Static and Dynamic. For
            static facets, all attributes must be defined in the schema. For dynamic facets, attributes can
            be defined during data plane operations. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.clouddirectory.create_facet(
                ctx,
                
                
                **{"Name": name, "SchemaArn": schema_arn, "Attributes": attributes, "ObjectType": object_type, "FacetStyle": facet_style}
            )
            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.clouddirectory.get_facet(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, schema_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a given Facet. All attributes and Rules that are associated with the facet will be deleted. Only
    development schema facets are allowed deletion.

    Args:
        name(Text): The name of the facet to delete.
        schema_arn(Text): The Amazon Resource Name (ARN) that is associated with the Facet. For more information, see
            arns.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

