#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT_DIR"

cargo build --release

APP_DIR="dist/WebVulnerabilityScanner.app"
rm -rf "$APP_DIR"
mkdir -p "$APP_DIR/Contents/MacOS" "$APP_DIR/Contents/Resources"

cp "target/release/web-vuln-scanner" "$APP_DIR/Contents/MacOS/web-vuln-scanner"
chmod +x "$APP_DIR/Contents/MacOS/web-vuln-scanner"

cat > "$APP_DIR/Contents/Info.plist" << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>CFBundleName</key>
  <string>Web Vulnerability Scanner</string>
  <key>CFBundleDisplayName</key>
  <string>Web Vulnerability Scanner</string>
  <key>CFBundleIdentifier</key>
  <string>io.github.web-vuln-scanner</string>
  <key>CFBundleVersion</key>
  <string>0.1.0</string>
  <key>CFBundleShortVersionString</key>
  <string>0.1.0</string>
  <key>CFBundlePackageType</key>
  <string>APPL</string>
  <key>CFBundleExecutable</key>
  <string>web-vuln-scanner</string>
  <key>NSHighResolutionCapable</key>
  <true/>
</dict>
</plist>
EOF

echo "macOS .app bundle created: $ROOT_DIR/$APP_DIR"
