#!/usr/bin/env bash
#
# Sync shared types from shared/types/ into each frontend service.
#
# The canonical source of truth is shared/types/*.ts.
# This script copies them into each service's local directory
# because Turbopack doesn't support tsconfig path aliases
# pointing outside the project root.
#
# Run this after modifying any file in shared/types/.

set -euo pipefail

ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
SHARED="$ROOT/shared/types"

echo "Syncing shared types from $SHARED..."

# Companion types
cp "$SHARED/companion.ts" "$ROOT/admin-lehrer/lib/companion/types.ts"
cp "$SHARED/companion.ts" "$ROOT/studio-v2/lib/companion/types.ts"

# Klausur-Korrektur types
cp "$SHARED/klausur.ts" "$ROOT/admin-lehrer/app/(admin)/education/klausur-korrektur/types.ts"
cp "$SHARED/klausur.ts" "$ROOT/studio-v2/app/korrektur/types.ts"
cp "$SHARED/klausur.ts" "$ROOT/website/app/admin/klausur-korrektur/types.ts"
cp "$SHARED/klausur.ts" "$ROOT/website/app/lehrer/klausur-korrektur/types.ts"
cp "$SHARED/klausur.ts" "$ROOT/website/components/klausur-korrektur/klausur-types.ts"

# OCR Labeling types
cp "$SHARED/ocr-labeling.ts" "$ROOT/admin-lehrer/app/(admin)/ai/ocr-labeling/types.ts"
cp "$SHARED/ocr-labeling.ts" "$ROOT/website/app/admin/ocr-labeling/types.ts"

echo "Done. Synced to 9 locations."
