#!/bin/bash

# Usage: ./get_featured_rights.sh [--party PARTY]

# Default: use CANTON_PROVIDER_PARTY from env if not provided
FEATURED_PARTY="${CANTON_PROVIDER_PARTY}"

# Parse optional --party argument
while [[ $# -gt 0 ]]; do
  case $1 in
    --party)
      FEATURED_PARTY="$2"
      shift 2
      ;;
    --help|-h)
      echo "Usage: $0 [--party PARTY]"
      echo ""
      echo "Fetch featured rights for the given provider party."
      echo "If --party is not provided, uses CANTON_PROVIDER_PARTY from the environment."
      exit 0
      ;;
    *)
      echo "Unknown option: $1"
      echo "Usage: $0 [--party PARTY]"
      exit 1
      ;;
  esac
done

# Use common authentication utility (robust path)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/common_auth.sh" "$@"

if [ -z "$FEATURED_PARTY" ]; then
  echo "Error: No provider party specified. Use --party or set CANTON_PROVIDER_PARTY in the environment."
  exit 1
fi

curl -s -X GET $WALLET_ENDPOINT/api/validator/v0/scan-proxy/featured-apps/$FEATURED_PARTY \
  -H "Authorization: Bearer $CANTON_TOKEN" | jq .

