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

hub.exec.boto3.client.glue.delete_resource_policy
hub.exec.boto3.client.glue.get_resource_policy
hub.exec.boto3.client.glue.put_resource_policy
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, policy_in_json: Text, resource_arn: Text = None, policy_hash_condition: Text = None, policy_exists_condition: Text = None, enable_hybrid: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Sets the Data Catalog resource policy for access control.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        policy_in_json(Text): Contains the policy document to set, in JSON format.
        resource_arn(Text, optional): Do not use. For internal use only. Defaults to None.
        policy_hash_condition(Text, optional): The hash value returned when the previous policy was set using PutResourcePolicy. Its purpose is
            to prevent concurrent modifications of a policy. Do not use this parameter if no previous policy
            has been set. Defaults to None.
        policy_exists_condition(Text, optional): A value of MUST_EXIST is used to update a policy. A value of NOT_EXIST is used to create a new
            policy. If a value of NONE or a null value is used, the call does not depend on the existence of
            a policy. Defaults to None.
        enable_hybrid(Text, optional): If 'TRUE', indicates that you are using both methods to grant cross-account access to Data
            Catalog resources:   By directly updating the resource policy with PutResourePolicy    By using
            the Grant permissions command on the Amazon Web Services Management Console.   Must be set to
            'TRUE' if you have already used the Management Console to grant cross-account access, otherwise
            the call fails. Default is 'FALSE'. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.glue.put_resource_policy(
                ctx,
                
                
                **{"PolicyInJson": policy_in_json, "ResourceArn": resource_arn, "PolicyHashCondition": policy_hash_condition, "PolicyExistsCondition": policy_exists_condition, "EnableHybrid": enable_hybrid}
            )
            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.glue.get_resource_policy(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, policy_hash_condition: Text = None, resource_arn: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a specified policy.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        policy_hash_condition(Text, optional): The hash value returned when this policy was set. Defaults to None.
        resource_arn(Text, optional): The ARN of the Glue resource for the resource policy to be deleted. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

