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

hub.exec.boto3.client.efs.delete_file_system_policy
hub.exec.boto3.client.efs.describe_file_system_policy
hub.exec.boto3.client.efs.put_file_system_policy
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, file_system_id: Text, policy: Text, bypass_policy_lockout_safety_check: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Applies an Amazon EFS FileSystemPolicy to an Amazon EFS file system. A file system policy is an IAM resource-
    based policy and can contain multiple policy statements. A file system always has exactly one file system
    policy, which can be the default policy or an explicit policy set or updated using this API operation. EFS file
    system policies have a 20,000 character limit. When an explicit policy is set, it overrides the default policy.
    For more information about the default file system policy, see Default EFS File System Policy.  EFS file system
    policies have a 20,000 character limit. This operation requires permissions for the
    elasticfilesystem:PutFileSystemPolicy action.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        file_system_id(Text): The ID of the EFS file system that you want to create or update the FileSystemPolicy for.
        policy(Text): The FileSystemPolicy that you're creating. Accepts a JSON formatted policy definition. EFS file
            system policies have a 20,000 character limit. To find out more about the elements that make up
            a file system policy, see EFS Resource-based Policies.
        bypass_policy_lockout_safety_check(bool, optional): (Optional) A flag to indicate whether to bypass the FileSystemPolicy lockout safety check. The
            policy lockout safety check determines whether the policy in the request will prevent the
            principal making the request will be locked out from making future PutFileSystemPolicy requests
            on the file system. Set BypassPolicyLockoutSafetyCheck to True only when you intend to prevent
            the principal that is making the request from making a subsequent PutFileSystemPolicy request on
            the file system. The default value is False. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.efs.file_system_policy.present:
                - name: value
                - file_system_id: value
                - policy: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.efs.file_system_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.efs.describe_file_system_policy(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.efs.put_file_system_policy(
                ctx,
                
                
                **{"FileSystemId": file_system_id, "Policy": policy, "BypassPolicyLockoutSafetyCheck": bypass_policy_lockout_safety_check}
            )
            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.efs.describe_file_system_policy(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, file_system_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the FileSystemPolicy for the specified file system. The default FileSystemPolicy goes into effect once
    the existing policy is deleted. For more information about the default file system policy, see Using Resource-
    based Policies with EFS. This operation requires permissions for the elasticfilesystem:DeleteFileSystemPolicy
    action.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        file_system_id(Text): Specifies the EFS file system for which to delete the FileSystemPolicy.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

