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

hub.exec.boto3.client.xray.create_group
hub.exec.boto3.client.xray.delete_group
hub.exec.boto3.client.xray.get_groups
hub.exec.boto3.client.xray.update_group
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, group_name: Text, filter_expression: Text = None, insights_configuration: Dict = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a group resource with a name and a filter expression.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        group_name(Text): The case-sensitive name of the new group. Default is a reserved name and names must be unique.
        filter_expression(Text, optional): The filter expression defining criteria by which to group traces. Defaults to None.
        insights_configuration(Dict, optional): The structure containing configurations related to insights.   The InsightsEnabled boolean can
            be set to true to enable insights for the new group or false to disable insights for the new
            group.   The NotifcationsEnabled boolean can be set to true to enable insights notifications for
            the new group. Notifications may only be enabled on a group with InsightsEnabled set to true. Defaults to None.
        tags(List, optional): A map that contains one or more tag keys and tag values to attach to an X-Ray group. For more
            information about ways to use tags, see Tagging AWS resources in the AWS General Reference. The
            following restrictions apply to tags:   Maximum number of user-applied tags per resource: 50
            Maximum tag key length: 128 Unicode characters   Maximum tag value length: 256 Unicode
            characters   Valid values for key and value: a-z, A-Z, 0-9, space, and the following characters:
            _ . : / = + - and @   Tag keys and values are case sensitive.   Don't use aws: as a prefix for
            keys; it's reserved for AWS use. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.xray.create_group(
                ctx,
                
                
                **{"GroupName": group_name, "FilterExpression": filter_expression, "InsightsConfiguration": insights_configuration, "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.xray.get_groups(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, group_name: Text = None, group_arn: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a group resource.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        group_name(Text, optional): The case-sensitive name of the group. Defaults to None.
        group_arn(Text, optional): The ARN of the group that was generated on creation. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

