name: Notify Monorepo of Changes

on:
  push:
    branches:
      - main

jobs:
  notify-monorepo:
    runs-on: ubuntu-latest
    steps:
      - name: Send repository dispatch to monorepo
        run: |
          # Determine which event type to send based on repository name
          REPO_NAME="${GITHUB_REPOSITORY#*/}"  # Gets 'python-sdk' from 'OpenRouterTeam/python-sdk'

          case "$REPO_NAME" in
            "typescript-sdk")
              EVENT_TYPE="sync-typescript-sdk"
              ;;
            "python-sdk")
              EVENT_TYPE="sync-python-sdk"
              ;;
            "ai-sdk-provider")
              EVENT_TYPE="sync-ai-sdk-provider"
              ;;
            "cli")
              EVENT_TYPE="sync-cli"
              ;;
            *)
              echo "Unknown repository: $REPO_NAME"
              exit 1
              ;;
          esac

          echo "Sending repository_dispatch event: $EVENT_TYPE"

          curl -L \
            -X POST \
            -H "Accept: application/vnd.github+json" \
            -H "Authorization: Bearer ${{ secrets.MONOREPO_SYNC_TOKEN }}" \
            -H "X-GitHub-Api-Version: 2022-11-28" \
            https://api.github.com/repos/OpenRouterTeam/openrouter-web/dispatches \
            -d "{\"event_type\":\"$EVENT_TYPE\",\"client_payload\":{\"repository\":\"$GITHUB_REPOSITORY\",\"ref\":\"$GITHUB_REF\",\"sha\":\"$GITHUB_SHA\"}}"

          echo "✅ Notification sent to monorepo"
