name: Code Quality Check

on:
  push:
    branches: [ main, develop ]
  pull_request:
    branches: [ main, develop ]

jobs:
  analyze:
    name: Flutter Analyze & Format Check
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Flutter
        uses: subosito/flutter-action@v2
        with:
          flutter-version: '3.27.1'
          channel: 'stable'

      - name: Get dependencies
        run: flutter pub get

      - name: Verify formatting
        run: dart format --set-exit-if-changed .
        continue-on-error: true

      - name: Analyze code
        run: flutter analyze --no-fatal-infos --no-fatal-warnings

      - name: Check for secrets.dart
        run: |
          if [ -f "lib/secrets.dart" ]; then
            echo "⚠️ Warning: secrets.dart found in repository!"
            echo "This file should be in .gitignore"
            exit 1
          else
            echo "✅ secrets.dart is properly excluded"
          fi

      - name: Run tests (if exist)
        run: flutter test
        continue-on-error: true

      - name: Summary
        if: always()
        run: |
          echo "## 🎯 Quality Check Summary" >> $GITHUB_STEP_SUMMARY
          echo "" >> $GITHUB_STEP_SUMMARY
          echo "- ✅ Code analyzed" >> $GITHUB_STEP_SUMMARY
          echo "- ✅ Format checked" >> $GITHUB_STEP_SUMMARY
          echo "- ✅ Security verified" >> $GITHUB_STEP_SUMMARY
          echo "" >> $GITHUB_STEP_SUMMARY
          echo "🤖 Automated by GitHub Actions" >> $GITHUB_STEP_SUMMARY
