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

hub.exec.boto3.client.redshift.authorize_endpoint_access
hub.exec.boto3.client.redshift.create_endpoint_access
hub.exec.boto3.client.redshift.delete_endpoint_access
hub.exec.boto3.client.redshift.describe_endpoint_access
hub.exec.boto3.client.redshift.modify_endpoint_access
hub.exec.boto3.client.redshift.revoke_endpoint_access
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, endpoint_name: Text, subnet_group_name: Text, cluster_identifier: Text = None, resource_owner: Text = None, vpc_security_group_ids: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a Redshift-managed VPC endpoint.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        cluster_identifier(Text, optional): The cluster identifier of the cluster to access. Defaults to None.
        resource_owner(Text, optional): The Amazon Web Services account ID of the owner of the cluster. This is only required if the
            cluster is in another Amazon Web Services account. Defaults to None.
        endpoint_name(Text): The Redshift-managed VPC endpoint name. An endpoint name must contain 1-30 characters. Valid
            characters are A-Z, a-z, 0-9, and hyphen(-). The first character must be a letter. The name
            can't contain two consecutive hyphens or end with a hyphen.
        subnet_group_name(Text): The subnet group from which Amazon Redshift chooses the subnet to deploy the endpoint.
        vpc_security_group_ids(List, optional): The security group that defines the ports, protocols, and sources for inbound traffic that you
            are authorizing into your endpoint. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.redshift.endpoint_access.present:
                - name: value
                - endpoint_name: value
                - subnet_group_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.redshift.endpoint_access.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.redshift.describe_endpoint_access(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.redshift.create_endpoint_access(
                ctx,
                
                
                **{"ClusterIdentifier": cluster_identifier, "ResourceOwner": resource_owner, "EndpointName": endpoint_name, "SubnetGroupName": subnet_group_name, "VpcSecurityGroupIds": vpc_security_group_ids}
            )
            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.redshift.describe_endpoint_access(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, endpoint_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a Redshift-managed VPC endpoint.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        endpoint_name(Text): The Redshift-managed VPC endpoint to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

