#!/bin/bash

# CIM Document Processor Backend Environment Setup
echo "Setting up environment variables for CIM Document Processor Backend..."

# Create .env file if it doesn't exist
if [ ! -f .env ]; then
    echo "Creating .env file..."
    cat > .env << EOF
# Environment Configuration for CIM Document Processor Backend

# Node Environment
NODE_ENV=development
PORT=5000

# Database Configuration
DATABASE_URL=postgresql://postgres:password@localhost:5432/cim_processor
DB_HOST=localhost
DB_PORT=5432
DB_NAME=cim_processor
DB_USER=postgres
DB_PASSWORD=password

# Redis Configuration
REDIS_URL=redis://localhost:6379
REDIS_HOST=localhost
REDIS_PORT=6379

# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
JWT_EXPIRES_IN=1h
JWT_REFRESH_SECRET=your-super-secret-refresh-key-change-this-in-production
JWT_REFRESH_EXPIRES_IN=7d

# File Upload Configuration
MAX_FILE_SIZE=52428800
UPLOAD_DIR=uploads
ALLOWED_FILE_TYPES=application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document

# LLM Configuration
LLM_PROVIDER=openai
OPENAI_API_KEY=your-openai-api-key-here
ANTHROPIC_API_KEY=your-anthropic-api-key-here
LLM_MODEL=gpt-4
LLM_MAX_TOKENS=4000
LLM_TEMPERATURE=0.1

# Storage Configuration (Local by default)
STORAGE_TYPE=local

# Security Configuration
BCRYPT_ROUNDS=12
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100

# Logging Configuration
LOG_LEVEL=info
LOG_FILE=logs/app.log

# Frontend URL (for CORS)
FRONTEND_URL=http://localhost:3000
EOF
    echo "✅ .env file created successfully!"
else
    echo "⚠️  .env file already exists. Skipping creation."
fi

echo ""
echo "📋 Next steps:"
echo "1. Edit the .env file with your actual database credentials"
echo "2. Add your OpenAI and/or Anthropic API keys"
echo "3. Update the JWT secrets for production"
echo "4. Run: npm run db:migrate (after setting up PostgreSQL)"
echo "5. Run: npm run dev"
echo ""
echo "🔧 Required services:"
echo "- PostgreSQL database"
echo "- Redis server"
echo "- OpenAI API key (or Anthropic API key)" 