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

hub.exec.boto3.client.lakeformation.deregister_resource
hub.exec.boto3.client.lakeformation.describe_resource
hub.exec.boto3.client.lakeformation.list_resources
hub.exec.boto3.client.lakeformation.register_resource
hub.exec.boto3.client.lakeformation.update_resource
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, resource_arn: Text, use_service_linked_role: bool = None, role_arn: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Registers the resource as managed by the Data Catalog. To add or update data, Lake Formation needs read/write
    access to the chosen Amazon S3 path. Choose a role that you know has permission to do this, or choose the
    AWSServiceRoleForLakeFormationDataAccess service-linked role. When you register the first Amazon S3 path, the
    service-linked role and a new inline policy are created on your behalf. Lake Formation adds the first path to
    the inline policy and attaches it to the service-linked role. When you register subsequent paths, Lake Formation
    adds the path to the existing policy. The following request registers a new location and gives AWS Lake
    Formation permission to use the service-linked role to access that location.  ResourceArn = arn:aws:s3:::my-
    bucket UseServiceLinkedRole = true  If UseServiceLinkedRole is not set to true, you must provide or set the
    RoleArn:  arn:aws:iam::12345:role/my-data-access-role

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        resource_arn(Text): The Amazon Resource Name (ARN) of the resource that you want to register.
        use_service_linked_role(bool, optional): Designates an AWS Identity and Access Management (IAM) service-linked role by registering this
            role with the Data Catalog. A service-linked role is a unique type of IAM role that is linked
            directly to Lake Formation. For more information, see Using Service-Linked Roles for Lake
            Formation. Defaults to None.
        role_arn(Text, optional): The identifier for the role that registers the resource. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.lakeformation.register_resource(
                ctx,
                
                
                **{"ResourceArn": resource_arn, "UseServiceLinkedRole": use_service_linked_role, "RoleArn": role_arn}
            )
            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.lakeformation.describe_resource(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, resource_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deregisters the resource as managed by the Data Catalog. When you deregister a path, Lake Formation removes the
    path from the inline policy attached to your service-linked role.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        resource_arn(Text): The Amazon Resource Name (ARN) of the resource that you want to deregister.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

