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

hub.exec.boto3.client.es.create_elasticsearch_domain
hub.exec.boto3.client.es.delete_elasticsearch_domain
hub.exec.boto3.client.es.describe_elasticsearch_domains
hub.exec.boto3.client.es.upgrade_elasticsearch_domain
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, domain_name: Text, elasticsearch_version: Text = None, elasticsearch_cluster_config: Dict = None, ebs_options: Dict = None, access_policies: Text = None, snapshot_options: Dict = None, vpc_options: Dict = None, cognito_options: Dict = None, encryption_at_rest_options: Dict = None, node_to_node_encryption_options: Dict = None, advanced_options: Dict = None, log_publishing_options: Dict = None, domain_endpoint_options: Dict = None, advanced_security_options: Dict = None, auto_tune_options: Dict = None, tag_list: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new Elasticsearch domain. For more information, see Creating Elasticsearch Domains in the Amazon
    Elasticsearch Service Developer Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        domain_name(Text): The name of the Elasticsearch domain that you are creating. Domain names are unique across the
            domains owned by an account within an AWS region. Domain names must start with a lowercase
            letter and can contain the following characters: a-z (lowercase), 0-9, and - (hyphen).
        elasticsearch_version(Text, optional): String of format X.Y to specify version for the Elasticsearch domain eg. "1.5" or "2.3". For
            more information, see Creating Elasticsearch Domains in the Amazon Elasticsearch Service
            Developer Guide. Defaults to None.
        elasticsearch_cluster_config(Dict, optional): Configuration options for an Elasticsearch domain. Specifies the instance type and number of
            instances in the domain cluster. Defaults to None.
        ebs_options(Dict, optional): Options to enable, disable and specify the type and size of EBS storage volumes. Defaults to None.
        access_policies(Text, optional):  IAM access policy as a JSON-formatted string. Defaults to None.
        snapshot_options(Dict, optional): Option to set time, in UTC format, of the daily automated snapshot. Default value is 0 hours. Defaults to None.
        vpc_options(Dict, optional): Options to specify the subnets and security groups for VPC endpoint. For more information, see
            Creating a VPC in VPC Endpoints for Amazon Elasticsearch Service Domains. Defaults to None.
        cognito_options(Dict, optional): Options to specify the Cognito user and identity pools for Kibana authentication. For more
            information, see Amazon Cognito Authentication for Kibana. Defaults to None.
        encryption_at_rest_options(Dict, optional): Specifies the Encryption At Rest Options. Defaults to None.
        node_to_node_encryption_options(Dict, optional): Specifies the NodeToNodeEncryptionOptions. Defaults to None.
        advanced_options(Dict, optional):  Option to allow references to indices in an HTTP request body. Must be false when configuring
            access to individual sub-resources. By default, the value is true. See Configuration Advanced
            Options for more information. Defaults to None.
        log_publishing_options(Dict, optional): Map of LogType and LogPublishingOption, each containing options to publish a given type of
            Elasticsearch log. Defaults to None.
        domain_endpoint_options(Dict, optional): Options to specify configuration that will be applied to the domain endpoint. Defaults to None.
        advanced_security_options(Dict, optional): Specifies advanced security options. Defaults to None.
        auto_tune_options(Dict, optional): Specifies Auto-Tune options. Defaults to None.
        tag_list(List, optional): A list of Tag added during domain creation. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.es.create_elasticsearch_domain(
                ctx,
                
                
                **{"DomainName": domain_name, "ElasticsearchVersion": elasticsearch_version, "ElasticsearchClusterConfig": elasticsearch_cluster_config, "EBSOptions": ebs_options, "AccessPolicies": access_policies, "SnapshotOptions": snapshot_options, "VPCOptions": vpc_options, "CognitoOptions": cognito_options, "EncryptionAtRestOptions": encryption_at_rest_options, "NodeToNodeEncryptionOptions": node_to_node_encryption_options, "AdvancedOptions": advanced_options, "LogPublishingOptions": log_publishing_options, "DomainEndpointOptions": domain_endpoint_options, "AdvancedSecurityOptions": advanced_security_options, "AutoTuneOptions": auto_tune_options, "TagList": tag_list}
            )
            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.es.describe_elasticsearch_domains(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, domain_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Permanently deletes the specified Elasticsearch domain and all of its data. Once a domain is deleted, it cannot
    be recovered.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        domain_name(Text): The name of the Elasticsearch domain that you want to permanently delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

