#!/bin/bash
# Create standard Maven project structure
# Usage: ./create-structure.sh <project_dir> <base_package>

set -e

PROJECT_DIR="${1:?Usage: create-structure.sh <project_dir> <base_package>}"
BASE_PACKAGE="${2:-com.example}"

# Convert package to path
PACKAGE_PATH=$(echo "$BASE_PACKAGE" | tr '.' '/')

echo "Creating Maven project structure..."
echo "  Project: $PROJECT_DIR"
echo "  Package: $BASE_PACKAGE"

# Create standard directories
mkdir -p "$PROJECT_DIR/src/main/java/$PACKAGE_PATH"
mkdir -p "$PROJECT_DIR/src/main/resources"
mkdir -p "$PROJECT_DIR/src/main/webapp/WEB-INF"
mkdir -p "$PROJECT_DIR/src/test/java/$PACKAGE_PATH"
mkdir -p "$PROJECT_DIR/src/test/resources"
mkdir -p "$PROJECT_DIR/lib"

# Create placeholder files
touch "$PROJECT_DIR/src/main/java/$PACKAGE_PATH/.gitkeep"
touch "$PROJECT_DIR/src/main/resources/.gitkeep"
touch "$PROJECT_DIR/src/test/java/$PACKAGE_PATH/.gitkeep"
touch "$PROJECT_DIR/src/test/resources/.gitkeep"

# Create .gitignore
cat > "$PROJECT_DIR/.gitignore" << 'EOF'
# Compiled class files
*.class

# Log files
*.log

# Package files
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar

# Build directories
target/
build/
out/

# IDE files
.idea/
*.iml
*.iws
*.ipr
.project
.classpath
.settings/
.factorypath
.vscode/
*.swp
*.swo

# OS files
.DS_Store
Thumbs.db

# Maven
.mvn/
mvnw
mvnw.cmd

# Gradle
.gradle/
gradlew
gradlew.cmd
EOF

echo "Structure created:"
echo "  $PROJECT_DIR/"
echo "  ├── src/"
echo "  │   ├── main/"
echo "  │   │   ├── java/$PACKAGE_PATH/"
echo "  │   │   ├── resources/"
echo "  │   │   └── webapp/WEB-INF/"
echo "  │   └── test/"
echo "  │       ├── java/$PACKAGE_PATH/"
echo "  │       └── resources/"
echo "  ├── lib/"
echo "  ├── .gitignore"
echo "  └── pom.xml (run generate-pom.sh to create)"
echo ""
echo "Next steps:"
echo "  1. Run decompile.sh to decompile class files"
echo "  2. Move decompiled .java files to src/main/java/"
echo "  3. Copy resources to src/main/resources/"
echo "  4. Run generate-pom.sh to create pom.xml"
