#!/bin/bash

set -e

TEAM_ID=$1
INSTALLATION_ID=$2
RULES_API_URL=$3

echo "Fetching CodeGuard rules..."
echo "Team ID: $TEAM_ID"
echo "Installation ID: $INSTALLATION_ID"

RESPONSE=$(curl -s -X POST "$RULES_API_URL" \
  -H "Content-Type: application/json" \
  -d "{
    \"installationId\": \"$INSTALLATION_ID\",
    \"teamId\": \"$TEAM_ID\"
  }")

echo "$RESPONSE" > rules-response.json

echo "Rules response:"
cat rules-response.json

echo "Rules fetched successfully"