#!/usr/bin/env bash
# Code generation for networks_sdk — clean lock/cache, resolve deps, run build_runner
#
# Usage:
#   bash scripts/gen.sh
#
# Generated files (*.freezed.dart, *.g.dart) are committed to git so that
# git-tag consumers can build without running build_runner themselves.

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SDK_DIR="$(dirname "$SCRIPT_DIR")"

cd "$SDK_DIR"

# ── Clean stale lock and tool cache ────────────────────────────────────────
echo "==> Removing pubspec.lock and .dart_tool..."
rm -rf pubspec.lock .dart_tool

# ── Resolve dependencies ────────────────────────────────────────────────────
echo "==> Running flutter pub get..."
flutter pub get

# ── Run build_runner ────────────────────────────────────────────────────────
echo "==> Running build_runner build..."
dart run build_runner build --delete-conflicting-outputs

echo ""
echo "networks_sdk code generation complete."
