name: backfill
on:
  workflow_dispatch:
    inputs:
      game:
        description: "Game key (cs2 or dota2)"
        required: true
        default: cs2
      names:
        description: 'Names JSON — array of {name, class, slot}'
        required: true

jobs:
  backfill:
    runs-on: s2-runner
    env:
      GAME: ${{ github.event.inputs.game }}
      RELEASE_BASE: ${{ github.server_url }}/${{ github.repository }}/releases/download
    steps:
      - uses: actions/checkout@v6.0.2

      - name: Fetch the model
        run: |
          mkdir -p in
          curl -fsSL -o in/model-$GAME.json "$RELEASE_BASE/$GAME-latest/model-$GAME.json"

      - name: Write the names file
        run: printf '%s' "$NAMES" > names.json
        env:
          NAMES: ${{ github.event.inputs.names }}

      - name: Build the deriver
        run: cargo build --release

      - name: Backfill
        run: |
          ./target/release/source2rosetta --game "$GAME" backfill \
            --corpus-model in/model-$GAME.json \
            --names        names.json \
            --out          history.json

      - uses: actions/upload-artifact@v4
        with:
          name: backfill-${{ env.GAME }}
          path: history.json
