plugins {
    id 'airbyte-docker-legacy'
    id 'airbyte-python'
}

dependencies {
    testFixtures(project(':airbyte-cdk:java:airbyte-cdk:airbyte-cdk-dependencies'))
}

// we need to access the sshtunneling script from airbyte-workers for ssh support
def copySshScript = tasks.register('copySshScript', Copy) {
    from "${project(':airbyte-cdk:java:airbyte-cdk:airbyte-cdk-dependencies').buildDir}/resources/testFixtures"
    into "${buildDir}"
    include "sshtunneling.sh"
}
copySshScript.configure {
    dependsOn project(':airbyte-cdk:java:airbyte-cdk:airbyte-cdk-dependencies').tasks.named('processTestFixturesResources')
}

// make sure the copy task above worked (if it fails, it fails silently annoyingly)
def checkSshScriptCopy = tasks.register('checkSshScriptCopy') {
    doFirst {
        assert file("${buildDir}/sshtunneling.sh").exists() : "Copy of sshtunneling.sh failed."
    }
}
checkSshScriptCopy.configure {
    dependsOn copySshScript
}

def generate = tasks.register('generate')
generate.configure {
    dependsOn checkSshScriptCopy
}

tasks.named('check').configure {
    dependsOn generate
}

tasks.named("jar").configure {
    dependsOn copySshScript
}

[
        'bigquery',
        'mysql',
        'postgres',
        'redshift',
        'snowflake',
        'oracle',
        'mssql',
        'clickhouse',
        'tidb',
].each {destinationName ->
    tasks.matching { it.name == 'integrationTestPython' }.configureEach {
        dependsOn project(":airbyte-integrations:connectors:destination-$destinationName").tasks.named('assemble')
    }
}
