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

hub.exec.boto3.client.dms.create_endpoint
hub.exec.boto3.client.dms.delete_endpoint
hub.exec.boto3.client.dms.describe_endpoints
hub.exec.boto3.client.dms.modify_endpoint
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, endpoint_identifier: Text, endpoint_type: Text, engine_name: Text, username: Text = None, password: Text = None, server_name: Text = None, port: int = None, database_name: Text = None, extra_connection_attributes: Text = None, kms_key_id: Text = None, tags: List = None, certificate_arn: Text = None, ssl_mode: Text = None, service_access_role_arn: Text = None, external_table_definition: Text = None, dynamo_db_settings: Dict = None, s3_settings: Dict = None, dms_transfer_settings: Dict = None, mongo_db_settings: Dict = None, kinesis_settings: Dict = None, kafka_settings: Dict = None, elasticsearch_settings: Dict = None, neptune_settings: Dict = None, redshift_settings: Dict = None, postgre_sql_settings: Dict = None, my_sql_settings: Dict = None, oracle_settings: Dict = None, sybase_settings: Dict = None, microsoft_sql_server_settings: Dict = None, ibm_db2_settings: Dict = None, resource_identifier: Text = None, doc_db_settings: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an endpoint using the provided settings.  For a MySQL source or target endpoint, don't explicitly
    specify the database using the DatabaseName request parameter on the CreateEndpoint API call. Specifying
    DatabaseName when you create a MySQL endpoint replicates all the task tables to this single database. For MySQL
    endpoints, you specify the database only when you specify the schema in the table-mapping rules of the DMS task.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        endpoint_identifier(Text): The database endpoint identifier. Identifiers must begin with a letter and must contain only
            ASCII letters, digits, and hyphens. They can't end with a hyphen, or contain two consecutive
            hyphens.
        endpoint_type(Text): The type of endpoint. Valid values are source and target.
        engine_name(Text): The type of engine for the endpoint. Valid values, depending on the EndpointType value, include
            "mysql", "oracle", "postgres", "mariadb", "aurora", "aurora-postgresql", "redshift", "s3",
            "db2", "azuredb", "sybase", "dynamodb", "mongodb", "kinesis", "kafka", "elasticsearch", "docdb",
            "sqlserver", and "neptune".
        username(Text, optional): The user name to be used to log in to the endpoint database. Defaults to None.
        password(Text, optional): The password to be used to log in to the endpoint database. Defaults to None.
        server_name(Text, optional): The name of the server where the endpoint database resides. Defaults to None.
        port(int, optional): The port used by the endpoint database. Defaults to None.
        database_name(Text, optional): The name of the endpoint database. For a MySQL source or target endpoint, do not specify
            DatabaseName. Defaults to None.
        extra_connection_attributes(Text, optional): Additional attributes associated with the connection. Each attribute is specified as a name-
            value pair associated by an equal sign (=). Multiple attributes are separated by a semicolon (;)
            with no additional white space. For information on the attributes available for connecting your
            source or target endpoint, see Working with DMS Endpoints in the Database Migration Service User
            Guide. Defaults to None.
        kms_key_id(Text, optional): An KMS key identifier that is used to encrypt the connection parameters for the endpoint. If you
            don't specify a value for the KmsKeyId parameter, then DMS uses your default encryption key. KMS
            creates the default encryption key for your account. Your account has a different default
            encryption key for each Region. Defaults to None.
        tags(List, optional): One or more tags to be assigned to the endpoint. Defaults to None.
        certificate_arn(Text, optional): The Amazon Resource Name (ARN) for the certificate. Defaults to None.
        ssl_mode(Text, optional): The Secure Sockets Layer (SSL) mode to use for the SSL connection. The default is none. Defaults to None.
        service_access_role_arn(Text, optional):  The Amazon Resource Name (ARN) for the service access role that you want to use to create the
            endpoint. The role must allow the iam:PassRole action. Defaults to None.
        external_table_definition(Text, optional): The external table definition. Defaults to None.
        dynamo_db_settings(Dict, optional): Settings in JSON format for the target Amazon DynamoDB endpoint. For information about other
            available settings, see Using Object Mapping to Migrate Data to DynamoDB in the Database
            Migration Service User Guide. Defaults to None.
        s3_settings(Dict, optional): Settings in JSON format for the target Amazon S3 endpoint. For more information about the
            available settings, see Extra Connection Attributes When Using Amazon S3 as a Target for DMS in
            the Database Migration Service User Guide. Defaults to None.
        dms_transfer_settings(Dict, optional): The settings in JSON format for the DMS transfer type of source endpoint.  Possible settings
            include the following:    ServiceAccessRoleArn - The IAM role that has permission to access the
            Amazon S3 bucket. The role must allow the iam:PassRole action.    BucketName - The name of the
            S3 bucket to use.   Shorthand syntax for these settings is as follows:
            ServiceAccessRoleArn=string,BucketName=string  JSON syntax for these settings is as follows: {
            "ServiceAccessRoleArn": "string", "BucketName": "string", }. Defaults to None.
        mongo_db_settings(Dict, optional): Settings in JSON format for the source MongoDB endpoint. For more information about the
            available settings, see Endpoint configuration settings when using MongoDB as a source for
            Database Migration Service in the Database Migration Service User Guide. Defaults to None.
        kinesis_settings(Dict, optional): Settings in JSON format for the target endpoint for Amazon Kinesis Data Streams. For more
            information about the available settings, see Using object mapping to migrate data to a Kinesis
            data stream in the Database Migration Service User Guide. Defaults to None.
        kafka_settings(Dict, optional): Settings in JSON format for the target Apache Kafka endpoint. For more information about the
            available settings, see Using object mapping to migrate data to a Kafka topic in the Database
            Migration Service User Guide. Defaults to None.
        elasticsearch_settings(Dict, optional): Settings in JSON format for the target Elasticsearch endpoint. For more information about the
            available settings, see Extra Connection Attributes When Using Elasticsearch as a Target for DMS
            in the Database Migration Service User Guide. Defaults to None.
        neptune_settings(Dict, optional): Settings in JSON format for the target Amazon Neptune endpoint. For more information about the
            available settings, see Specifying graph-mapping rules using Gremlin and R2RML for Amazon
            Neptune as a target in the Database Migration Service User Guide. Defaults to None.
        redshift_settings(Dict, optional): Provides information that defines an Amazon Redshift endpoint. Defaults to None.
        postgre_sql_settings(Dict, optional): Settings in JSON format for the source and target PostgreSQL endpoint. For information about
            other available settings, see Extra connection attributes when using PostgreSQL as a source for
            DMS and  Extra connection attributes when using PostgreSQL as a target for DMS in the Database
            Migration Service User Guide. Defaults to None.
        my_sql_settings(Dict, optional): Settings in JSON format for the source and target MySQL endpoint. For information about other
            available settings, see Extra connection attributes when using MySQL as a source for DMS and
            Extra connection attributes when using a MySQL-compatible database as a target for DMS in the
            Database Migration Service User Guide. Defaults to None.
        oracle_settings(Dict, optional): Settings in JSON format for the source and target Oracle endpoint. For information about other
            available settings, see Extra connection attributes when using Oracle as a source for DMS and
            Extra connection attributes when using Oracle as a target for DMS in the Database Migration
            Service User Guide. Defaults to None.
        sybase_settings(Dict, optional): Settings in JSON format for the source and target SAP ASE endpoint. For information about other
            available settings, see Extra connection attributes when using SAP ASE as a source for DMS and
            Extra connection attributes when using SAP ASE as a target for DMS in the Database Migration
            Service User Guide. Defaults to None.
        microsoft_sql_server_settings(Dict, optional): Settings in JSON format for the source and target Microsoft SQL Server endpoint. For information
            about other available settings, see Extra connection attributes when using SQL Server as a
            source for DMS and  Extra connection attributes when using SQL Server as a target for DMS in the
            Database Migration Service User Guide. Defaults to None.
        ibm_db2_settings(Dict, optional): Settings in JSON format for the source IBM Db2 LUW endpoint. For information about other
            available settings, see Extra connection attributes when using Db2 LUW as a source for DMS in
            the Database Migration Service User Guide. Defaults to None.
        resource_identifier(Text, optional): A friendly name for the resource identifier at the end of the EndpointArn response parameter
            that is returned in the created Endpoint object. The value for this parameter can have up to 31
            characters. It can contain only ASCII letters, digits, and hyphen ('-'). Also, it can't end with
            a hyphen or contain two consecutive hyphens, and can only begin with a letter, such as Example-
            App-ARN1. For example, this value might result in the EndpointArn value arn:aws:dms:eu-
            west-1:012345678901:rep:Example-App-ARN1. If you don't specify a ResourceIdentifier value, DMS
            generates a default identifier value for the end of EndpointArn. Defaults to None.
        doc_db_settings(Dict, optional): Provides information that defines a DocumentDB endpoint. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.dms.endpoint.present:
                - name: value
                - endpoint_identifier: value
                - endpoint_type: value
                - engine_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.dms.endpoint.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.dms.describe_endpoints(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.dms.create_endpoint(
                ctx,
                
                
                **{"EndpointIdentifier": endpoint_identifier, "EndpointType": endpoint_type, "EngineName": engine_name, "Username": username, "Password": password, "ServerName": server_name, "Port": port, "DatabaseName": database_name, "ExtraConnectionAttributes": extra_connection_attributes, "KmsKeyId": kms_key_id, "Tags": tags, "CertificateArn": certificate_arn, "SslMode": ssl_mode, "ServiceAccessRoleArn": service_access_role_arn, "ExternalTableDefinition": external_table_definition, "DynamoDbSettings": dynamo_db_settings, "S3Settings": s3_settings, "DmsTransferSettings": dms_transfer_settings, "MongoDbSettings": mongo_db_settings, "KinesisSettings": kinesis_settings, "KafkaSettings": kafka_settings, "ElasticsearchSettings": elasticsearch_settings, "NeptuneSettings": neptune_settings, "RedshiftSettings": redshift_settings, "PostgreSQLSettings": postgre_sql_settings, "MySQLSettings": my_sql_settings, "OracleSettings": oracle_settings, "SybaseSettings": sybase_settings, "MicrosoftSQLServerSettings": microsoft_sql_server_settings, "IBMDb2Settings": ibm_db2_settings, "ResourceIdentifier": resource_identifier, "DocDbSettings": doc_db_settings}
            )
            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.dms.describe_endpoints(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, endpoint_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified endpoint.  All tasks associated with the endpoint must be deleted before you can delete
    the endpoint.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        endpoint_arn(Text): The Amazon Resource Name (ARN) string that uniquely identifies the endpoint.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

