#!/bin/bash
set -e

# Define variables
IDL_ZIP_URL="https://bucket.gitgo.app/solana/idl.zip"
TYPES_ZIP_URL="https://bucket.gitgo.app/solana/types.zip"
DEST_DIR="$(dirname "$0")/../assets/solana"
TMP_DIR="$(mktemp -d)"

# Download the zip files
curl -L "$IDL_ZIP_URL" -o "$TMP_DIR/idl.zip"
curl -L "$TYPES_ZIP_URL" -o "$TMP_DIR/types.zip"

# Create destination directory if it doesn't exist
mkdir -p "$DEST_DIR"

# Unzip into the destination directory
unzip -o "$TMP_DIR/idl.zip" -d "$DEST_DIR"
unzip -o "$TMP_DIR/types.zip" -d "$DEST_DIR"

# Clean up
rm -rf "$TMP_DIR"

echo "IDL and types files fetched and extracted to $DEST_DIR"