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

hub.exec.boto3.client.cognito_idp.create_group
hub.exec.boto3.client.cognito_idp.delete_group
hub.exec.boto3.client.cognito_idp.get_group
hub.exec.boto3.client.cognito_idp.list_groups
hub.exec.boto3.client.cognito_idp.update_group
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, group_name: Text, user_pool_id: Text, description: Text = None, role_arn: Text = None, precedence: int = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new group in the specified user pool. Calling this action requires developer credentials.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        group_name(Text): The name of the group. Must be unique.
        user_pool_id(Text): The user pool ID for the user pool.
        description(Text, optional): A string containing the description of the group. Defaults to None.
        role_arn(Text, optional): The role ARN for the group. Defaults to None.
        precedence(int, optional): A nonnegative integer value that specifies the precedence of this group relative to the other
            groups that a user can belong to in the user pool. Zero is the highest precedence value. Groups
            with lower Precedence values take precedence over groups with higher or null Precedence values.
            If a user belongs to two or more groups, it is the group with the lowest precedence value whose
            role ARN will be used in the cognito:roles and cognito:preferred_role claims in the user's
            tokens. Two groups can have the same Precedence value. If this happens, neither group takes
            precedence over the other. If two groups with the same Precedence have the same role ARN, that
            role is used in the cognito:preferred_role claim in tokens for users in each group. If the two
            groups have different role ARNs, the cognito:preferred_role claim is not set in users' tokens.
            The default Precedence value is null. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.cognito_idp.create_group(
                ctx,
                
                
                **{"GroupName": group_name, "UserPoolId": user_pool_id, "Description": description, "RoleArn": role_arn, "Precedence": precedence}
            )
            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.cognito_idp.get_group(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, group_name: Text, user_pool_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a group. Calling this action requires developer credentials.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        group_name(Text): The name of the group.
        user_pool_id(Text): The user pool ID for the user pool.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

