#!/bin/bash

# این اسکریپت باید روی سیستمی با دسترسی به اینترنت اجرا شود

PRISMA_VERSION=$(node -p "require('./package.json').dependencies['@prisma/client']" | tr -d '^~')
COMMIT_HASH="c2990dca591cba766e3b7ef5d9e8a84796e47ab7"
PLATFORM="linux-musl-openssl-3.0.x"

mkdir -p prisma/engines

echo "Downloading Prisma engines for version $PRISMA_VERSION..."

# Download query engine
curl -L "https://binaries.prisma.sh/all_commits/${COMMIT_HASH}/${PLATFORM}/query-engine.gz" \
  | gunzip > prisma/engines/query-engine
chmod +x prisma/engines/query-engine

# Download schema engine  
curl -L "https://binaries.prisma.sh/all_commits/${COMMIT_HASH}/${PLATFORM}/schema-engine.gz" \
  | gunzip > prisma/engines/schema-engine
chmod +x prisma/engines/schema-engine

echo "Engines downloaded successfully!"
echo "Now commit these files:"
echo "git add prisma/engines"
echo "git commit -m 'Add Prisma engines for offline deployment'"
echo "git push"
