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

hub.exec.boto3.client.ec2.create_network_interface_permission
hub.exec.boto3.client.ec2.delete_network_interface_permission
hub.exec.boto3.client.ec2.describe_network_interface_permissions
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, network_interface_id: Text, permission: Text, aws_account_id: Text = None, aws_service: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Grants an Amazon Web Services-authorized account permission to attach the specified network interface to an
    instance in their account. You can grant permission to a single Amazon Web Services account only, and only one
    account at a time.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        network_interface_id(Text): The ID of the network interface.
        aws_account_id(Text, optional): The Amazon Web Services account ID. Defaults to None.
        aws_service(Text, optional): The Amazon Web Service. Currently not supported. Defaults to None.
        permission(Text): The type of permission to grant.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.ec2.network_interface_permission.present:
                - name: value
                - network_interface_id: value
                - permission: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ec2.network_interface_permission.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.ec2.describe_network_interface_permissions(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.create_network_interface_permission(
                ctx,
                DryRun=ctx.test,
                
                **{"NetworkInterfaceId": network_interface_id, "AwsAccountId": aws_account_id, "AwsService": aws_service, "Permission": permission}
            )
            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.ec2.describe_network_interface_permissions(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, network_interface_permission_id: Text, force: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a permission for a network interface. By default, you cannot delete the permission if the account for
    which you're removing the permission has attached the network interface to an instance. However, you can force
    delete the permission, regardless of any attachment.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        network_interface_permission_id(Text): The ID of the network interface permission.
        force(bool, optional): Specify true to remove the permission even if the network interface is attached to an instance. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.ec2.delete_network_interface_permission(
                ctx,
                DryRun=ctx.test,
                
                **{"NetworkInterfacePermissionId": network_interface_permission_id, "Force": force}
            )
            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.ec2.describe_network_interface_permissions(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

