#!/bin/bash
# Generate DBC Go packages from DBC files
# Usage: ./scripts/generate-dbc.sh /path/to/dbc/files

set -e

DBC_SOURCE="${1:-}"

if [ -z "$DBC_SOURCE" ]; then
    echo "Usage: $0 /path/to/dbc/files"
    echo ""
    echo "DBC files should be in a directory structure like:"
    echo "  dbc/"
    echo "    fm29_frs90.dbc"
    echo "    fm29_frsd0.dbc"
    echo "    ..."
    exit 1
fi

if [ ! -d "$DBC_SOURCE" ]; then
    echo "Error: DBC source directory not found: $DBC_SOURCE"
    exit 1
fi

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

echo "Generating DBC packages from: $DBC_SOURCE"
echo "Output directory: $REPO_ROOT/pkg/dbc"

go run "$REPO_ROOT/pkg/can-go/cmd/cantool" generate "$DBC_SOURCE" "$REPO_ROOT/pkg/dbc"

echo "Done! Generated packages in pkg/dbc/"
