# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
# 
#   http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
# 
import pytest
import data_pipeline.extractor.extractor
import tests.unittest_utils as unittest_utils
import data_pipeline.constants.const as const

import data_pipeline.audit.custom_orm as custom_orm
from data_pipeline.audit.custom_orm import (ProcessControl,
                                            ProcessControlDetail,
                                            SourceSystemProfile)


EXPECTED_PROCESS_CONTROL_INSERT_SQL = """
        INSERT INTO ctl.process_control (
            process_code,
            duration,
            comment,
            status,
            process_starttime,
            process_endtime,
            infolog,
            errorlog,
            profile_name,
            profile_version,
            process_name,
            min_lsn,
            max_lsn,
            filename,
            executor_run_id,
            executor_status,
            source_system_code,
            source_system_type,
            source_region,
            target_system,
            target_region,
            target_system_type,
            object_list,
            total_count
        ) VALUES (
            %s,
            %s,
            %s,
            %s,
            %s,
            %s,
            %s,
            %s,
            %s,
            %s,
            %s,
            %s,
            %s,
            %s,
            %s,
            %s,
            %s,
            %s,
            %s,
            %s,
            %s,
            %s,
            %s,
            %s
        ) RETURNING id"""


def get_expected_process_control_values(mocker):
    return ['InitSync', 0, '', 'IN_PROGRESS', mocker.ANY, mocker.ANY, '', '',
            'myprofile', 1, 'InitSync', 123, 456, mocker.ANY, 0, '',
            'myprofile', 'oracle', 'sys', 'myprofile', 'ctl', 'postgres', '', 0]


EXPECTED_PROCESS_CONTROL_DETAIL_INSERT_SQL = """
        INSERT INTO ctl.process_control_detail (
            process_code,
            duration,
            comment,
            status,
            process_starttime,
            process_endtime,
            infolog,
            errorlog,
            run_id,
            object_schema,
            object_name,
            source_row_count,
            insert_row_count,