name: Documentation CI/CD

on:
  push:
    branches: [ main, develop ]
    paths:
      - 'docs/**'
      - '**/*.md'
      - '**/src/main/kotlin/**/*.kt'
  pull_request:
    branches: [ main ]
    paths:
      - 'docs/**'
      - '**/*.md'

jobs:
  validate-documentation:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '18'

      - name: Install markdown-link-check
        run: npm install -g markdown-link-check

      - name: Check markdown links
        run: |
          find . -name "*.md" -not -path "./node_modules/*" | \
          xargs markdown-link-check --config .github/markdown-link-check.json

      - name: Validate documentation structure
        run: |
          echo "Checking documentation completeness..."
          ./scripts/validate-docs.sh

  generate-api-docs:
    runs-on: ubuntu-latest
    needs: validate-documentation
    steps:
      - uses: actions/checkout@v4

      - name: Setup Java 21
        uses: actions/setup-java@v4
        with:
          java-version: '21'
          distribution: 'temurin'

      - name: Generate OpenAPI documentation
        run: |
          ./gradlew generateOpenApiDocs

      - name: Deploy documentation
        if: github.ref == 'refs/heads/main'
        run: |
          echo "Deploying documentation to GitHub Pages..."
