pipeline {
  agent any
  parameters {
    choice(name: 'SERVICE_NAME', choices: ['all', 'frontend', 'backend', 'docker-only'], description: '배포 대상')
    booleanParam(name: 'DEPLOY_APPROVED', defaultValue: true, description: '배포 승인')
  }
  stages {
    stage('Approve') {
      steps {
        script {
          if (!params.DEPLOY_APPROVED) {
            error('DEPLOY_APPROVED=true 필요')
          }
        }
      }
    }
    stage('Deploy') {
      steps {
        sh '''
          set -euo pipefail
          export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:$PATH"
          echo "=== BillCare Jenkins Build #${BUILD_NUMBER} ==="
          echo "시각: $(date)"
          SERVICE_NAME=${SERVICE_NAME} /Volumes/ADATA/git/deploy-billcare.sh
        '''
      }
    }
  }
  post {
    always {
      sh 'tail -40 /Volumes/ADATA/logs/deploy/billcare-deploy.log || true'
    }
  }
}
