name: Deploy
on:
  push:
    branches: [main]
    paths: ['products/01-llm-cost-router/src/**', 'products/01-llm-cost-router/Cargo.*']

jobs:
  deploy-proxy:
    runs-on: ubuntu-latest
    needs: []
    steps:
      - uses: actions/checkout@v4

      - uses: superfly/flyctl-actions/setup-flyctl@master

      - name: Deploy proxy to Fly.io
        run: flyctl deploy --config fly.proxy.toml --remote-only
        working-directory: products/01-llm-cost-router
        env:
          FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

  deploy-api:
    runs-on: ubuntu-latest
    needs: []
    steps:
      - uses: actions/checkout@v4

      - uses: superfly/flyctl-actions/setup-flyctl@master

      - name: Deploy API to Fly.io
        run: flyctl deploy --config fly.api.toml --remote-only
        working-directory: products/01-llm-cost-router
        env:
          FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

  deploy-ui:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: '22'

      - name: Build UI
        run: |
          cd products/01-llm-cost-router/ui
          npm ci
          npm run build

      - name: Deploy to Cloudflare Pages
        run: |
          npx wrangler pages deploy products/01-llm-cost-router/ui/dist \
            --project-name=dd0c-route \
            --branch=main
        env:
          CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
