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

hub.exec.boto3.client.cognito_idp.create_resource_server
hub.exec.boto3.client.cognito_idp.delete_resource_server
hub.exec.boto3.client.cognito_idp.describe_resource_server
hub.exec.boto3.client.cognito_idp.list_resource_servers
hub.exec.boto3.client.cognito_idp.update_resource_server
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, user_pool_id: Text, identifier: Text, scopes: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new OAuth2.0 resource server and defines custom scopes in it.

    Args:
        name(Text): A friendly name for the resource server.
        user_pool_id(Text): The user pool ID for the user pool.
        identifier(Text): A unique resource server identifier for the resource server. This could be an HTTPS endpoint
            where the resource server is located. For example, https://my-weather-api.example.com.
        scopes(List, optional): A list of scopes. Each scope is map, where the keys are name and description. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.cognito_idp.create_resource_server(
                ctx,
                
                
                **{"Name": name, "UserPoolId": user_pool_id, "Identifier": identifier, "Scopes": scopes}
            )
            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.describe_resource_server(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, user_pool_id: Text, identifier: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a resource server.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        user_pool_id(Text): The user pool ID for the user pool that hosts the resource server.
        identifier(Text): The identifier for the resource server.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

