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

hub.exec.boto3.client.iam.create_group
hub.exec.boto3.client.iam.delete_group
hub.exec.boto3.client.iam.get_group
hub.exec.boto3.client.iam.list_groups
hub.exec.boto3.client.iam.update_group
resource = hub.tool.boto3.resource.create(ctx, "iam", "Group", name)
hub.tool.boto3.resource.exec(resource, add_user, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, attach_policy, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, create, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, create_policy, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, delete, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, detach_policy, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, remove_user, *args, **kwargs)
hub.tool.boto3.resource.exec(resource, update, *args, **kwargs)
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, group_name: Text, path: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new group.  For information about the number of groups you can create, see IAM and STS quotas in the
    IAM User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        path(Text, optional):  The path to the group. For more information about paths, see IAM identifiers in the IAM User
            Guide. This parameter is optional. If it is not included, it defaults to a slash (/). This
            parameter allows (through its regex pattern) a string of characters consisting of either a
            forward slash (/) by itself or a string that must begin and end with forward slashes. In
            addition, it can contain any ASCII character from the ! (\u0021) through the DEL character
            (\u007F), including most punctuation characters, digits, and upper and lowercased letters. Defaults to None.
        group_name(Text): The name of the group to create. Do not include the path in this value. IAM user, group, role,
            and policy names must be unique within the account. Names are not distinguished by case. For
            example, you cannot create resources named both "MyResource" and "myresource".

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.iam.group.present:
                - name: value
                - group_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iam.group.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    resource = hub.tool.boto3.resource.create(ctx, "iam", "Group", name)
    before = await hub.tool.boto3.resource.describe(resource)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iam.create_group(
                ctx,
                
                
                **{"Path": path, "GroupName": group_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.tool.boto3.resource.describe(resource)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, group_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified IAM group. The group must not contain any users or have any attached policies.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        group_name(Text): The name of the IAM group to delete. This parameter allows (through its regex pattern) a string
            of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can
            also include any of the following characters: _+=,.@-.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.iam.group.absent:
                - name: value
                - group_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iam.group.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    resource = hub.tool.boto3.resource.create(ctx, "iam", "Group", name)

    before = await hub.tool.boto3.resource.describe(resource)

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

