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

hub.exec.boto3.client.dms.create_replication_task
hub.exec.boto3.client.dms.delete_replication_task
hub.exec.boto3.client.dms.describe_replication_tasks
hub.exec.boto3.client.dms.modify_replication_task
hub.exec.boto3.client.dms.move_replication_task
hub.exec.boto3.client.dms.start_replication_task
hub.exec.boto3.client.dms.stop_replication_task
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, replication_task_identifier: Text, source_endpoint_arn: Text, target_endpoint_arn: Text, replication_instance_arn: Text, migration_type: Text, table_mappings: Text, replication_task_settings: Text = None, cdc_start_time: Text = None, cdc_start_position: Text = None, cdc_stop_position: Text = None, tags: List = None, task_data: Text = None, resource_identifier: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a replication task using the specified parameters.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        replication_task_identifier(Text): An identifier for the replication task. Constraints:   Must contain 1-255 alphanumeric
            characters or hyphens.   First character must be a letter.   Cannot end with a hyphen or contain
            two consecutive hyphens.
        source_endpoint_arn(Text): An Amazon Resource Name (ARN) that uniquely identifies the source endpoint.
        target_endpoint_arn(Text): An Amazon Resource Name (ARN) that uniquely identifies the target endpoint.
        replication_instance_arn(Text): The Amazon Resource Name (ARN) of a replication instance.
        migration_type(Text): The migration type. Valid values: full-load | cdc | full-load-and-cdc.
        table_mappings(Text): The table mappings for the task, in JSON format. For more information, see Using Table Mapping
            to Specify Task Settings in the Database Migration Service User Guide.
        replication_task_settings(Text, optional): Overall settings for the task, in JSON format. For more information, see Specifying Task
            Settings for Database Migration Service Tasks in the Database Migration Service User Guide. Defaults to None.
        cdc_start_time(Text, optional): Indicates the start time for a change data capture (CDC) operation. Use either CdcStartTime or
            CdcStartPosition to specify when you want a CDC operation to start. Specifying both values
            results in an error. Timestamp Example: --cdc-start-time “2018-03-08T12:12:12”. Defaults to None.
        cdc_start_position(Text, optional): Indicates when you want a change data capture (CDC) operation to start. Use either
            CdcStartPosition or CdcStartTime to specify when you want a CDC operation to start. Specifying
            both values results in an error.  The value can be in date, checkpoint, or LSN/SCN format. Date
            Example: --cdc-start-position “2018-03-08T12:12:12” Checkpoint Example: --cdc-start-position
            "checkpoint:V1#27#mysql-bin-changelog.157832:1975:-1:2002:677883278264080:mysql-bin-
            changelog.157832:1876#0#0#*#0#93" LSN Example: --cdc-start-position “mysql-bin-
            changelog.000024:373”  When you use this task setting with a source PostgreSQL database, a
            logical replication slot should already be created and associated with the source endpoint. You
            can verify this by setting the slotName extra connection attribute to the name of this logical
            replication slot. For more information, see Extra Connection Attributes When Using PostgreSQL as
            a Source for DMS. Defaults to None.
        cdc_stop_position(Text, optional): Indicates when you want a change data capture (CDC) operation to stop. The value can be either
            server time or commit time. Server time example: --cdc-stop-position
            “server_time:2018-02-09T12:12:12” Commit time example: --cdc-stop-position “commit_time:
            2018-02-09T12:12:12 “. Defaults to None.
        tags(List, optional): One or more tags to be assigned to the replication task. Defaults to None.
        task_data(Text, optional): Supplemental information that the task requires to migrate the data for certain source and
            target endpoints. For more information, see Specifying Supplemental Data for Task Settings 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.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.dms.replication_task.present:
                - name: value
                - replication_task_identifier: value
                - source_endpoint_arn: value
                - target_endpoint_arn: value
                - replication_instance_arn: value
                - migration_type: value
                - table_mappings: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.dms.replication_task.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_replication_tasks(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.dms.create_replication_task(
                ctx,
                
                
                **{"ReplicationTaskIdentifier": replication_task_identifier, "SourceEndpointArn": source_endpoint_arn, "TargetEndpointArn": target_endpoint_arn, "ReplicationInstanceArn": replication_instance_arn, "MigrationType": migration_type, "TableMappings": table_mappings, "ReplicationTaskSettings": replication_task_settings, "CdcStartTime": cdc_start_time, "CdcStartPosition": cdc_start_position, "CdcStopPosition": cdc_stop_position, "Tags": tags, "TaskData": task_data, "ResourceIdentifier": resource_identifier}
            )
            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_replication_tasks(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, replication_task_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified replication task.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        replication_task_arn(Text): The Amazon Resource Name (ARN) of the replication task to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

