pipeline {
    agent any
    stages {
        stage('Copy Key Properties') {
            steps {
                sh 'cp /var/lib/jenkins/key.properties "$WORKSPACE/refilc/android/key.properties"'
            }
        }
        stage('Flutter Doctor') {
            steps {
                sh 'flutter doctor'
            }
        }
        stage('Dependencies') {
            steps {
                sh 'cd refilc && flutter pub get'
            }
        }
        stage('Build') {
            steps {
                sh '''
                    cd refilc
                    flutter build apk --release
                    flutter build appbundle --release
                '''
            }
        }
        stage('Archive') {
            steps {
                archiveArtifacts artifacts: 'refilc/build/app/outputs/flutter-apk/app-release.apk,refilc/build/app/outputs/bundle/release/app-release.aab',
                                 fingerprint: true
            }
        }
    }
    post {
        always {
            deleteDir()
        }
    }
}