pipeline {
    agent any

    options {
        ansiColor('xterm')
        disableConcurrentBuilds()
        timestamps()
        timeout(time: 20, unit: 'MINUTES')
        buildDiscarder(logRotator(numToKeepStr: '60'))
    }

    parameters {
        choice(
            name: 'SNOWFLAKE_SCHEMA',
            choices: ['PROD_OWS_TIMED_RELEASE_OWS_TIMED_RELEASE_SCHEDULE', 'QA'],
            description: 'The snowflake schema for the TIMED_RELEASES_STORE_LINKS table'
        )
    }

    triggers {
        cron('H 4 * * *') // Runs once daily around 04:00
    }

    stages {
        stage('Load Shared Libraries') {
            steps {
                library "jenkins-global-libraries@master"
            }
        }

        stage('Run Playwright E2E Prod Tests') {
            environment {
                TAGS = "@deezer-scraper"
            }
            steps {
                script {
                    playwrightTests(
                        tags: env.TAGS,
                        envVars: [SNOWFLAKE_SCHEMA: params.SNOWFLAKE_SCHEMA],
                        slackNotificationChannels: ['#data-alerts']
                    )
                }
            }
        }
    }
}
