pipeline {
    agent { label 'windows' }
    
    options {
        timestamps()
        disableConcurrentBuilds()
        timeout(time: 30, unit: 'MINUTES')
    }
    
    triggers {
        pollSCM('')
    }
    
    stages {
        stage('Checkout') {
            steps {
                checkout scm
            }
        }
        
        stage('Build') {
            parallel {
                stage('Build Debug') { /* … */ }
                stage('Build Release') { /* … */ }
            }
        }
        
        stage('Package') {
            parallel {
                stage('Package Debug') { /* … */ }
                stage('Package Release') { /* … */ }
            }
        }
        
        stage('Archive Artifacts') {
            steps {
                archiveArtifacts artifacts: 'builds/*.zip', fingerprint: true
            }
        }
    }
    
    post {
        success {
            script {
                // Construis la liste des URLs d'artefacts
                def debugUrl   = "${env.BUILD_URL}artifact/builds/KhaoticEngineReborn_Debug.zip"
                def releaseUrl = "${env.BUILD_URL}artifact/builds/KhaoticEngineReborn_Release.zip"
                
                // Appelle l'endpoint de ton bot pour envoyer le DM
                sh """
                    curl -X POST http://localhost:2500/ci-notify \
                         -H 'Content-Type: application/json' \
                         -d '{
                               "userId": "TON_USER_ID_DISCORD",
                               "status": "success",
                               "urls": ["${debugUrl}", "${releaseUrl}"]
                             }'
                """
            }
        }
        failure {
            script {
                sh """
                    curl -X POST http://localhost:2500/ci-notify \
                         -H 'Content-Type: application/json' \
                         -d '{
                               "userId": "TON_USER_ID_DISCORD",
                               "status": "failure",
                               "urls": []
                             }'
                """
            }
        }
        always {
            cleanWs(deleteDirs: true, disableDeferredWipeout: true, notFailBuild: true)
        }
    }
}
