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

hub.exec.boto3.client.workspaces.associate_ip_groups
hub.exec.boto3.client.workspaces.create_ip_group
hub.exec.boto3.client.workspaces.delete_ip_group
hub.exec.boto3.client.workspaces.describe_ip_groups
hub.exec.boto3.client.workspaces.disassociate_ip_groups
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, group_name: Text, group_desc: Text = None, user_rules: List = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an IP access control group. An IP access control group provides you with the ability to control the IP
    addresses from which users are allowed to access their WorkSpaces. To specify the CIDR address ranges, add rules
    to your IP access control group and then associate the group with your directory. You can add rules when you
    create the group or at any time using AuthorizeIpRules. There is a default IP access control group associated
    with your directory. If you don't associate an IP access control group with your directory, the default group is
    used. The default group includes a default rule that allows users to access their WorkSpaces from anywhere. You
    cannot modify the default IP access control group for your directory.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        group_name(Text): The name of the group.
        group_desc(Text, optional): The description of the group. Defaults to None.
        user_rules(List, optional): The rules to add to the group. Defaults to None.
        tags(List, optional): The tags. Each WorkSpaces resource can have a maximum of 50 tags. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.workspaces.create_ip_group(
                ctx,
                
                
                **{"GroupName": group_name, "GroupDesc": group_desc, "UserRules": user_rules, "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.workspaces.describe_ip_groups(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, group_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified IP access control group. You cannot delete an IP access control group that is associated
    with a directory.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        group_id(Text): The identifier of the IP access control group.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

