#!/bin/bash

# Production startup script for La Tarte Next.js application
# This script builds and starts the application on port 3011

echo "🚀 Starting La Tarte production server on port 3011..."

# Check if .env file exists
if [ ! -f .env ]; then
  echo "⚠️  Warning: .env file not found. Creating from .env.example..."
  if [ -f .env.example ]; then
    cp .env.example .env
    echo "✅ Created .env file from .env.example"
    echo "🔧 Please update .env with your production values"
  else
    echo "❌ No .env.example found. Please create .env manually"
    exit 1
  fi
fi

# Install dependencies
echo "📦 Installing dependencies..."
npm ci --only=production

# Build the application
echo "🔨 Building application..."
npm run build

# Check if build was successful
if [ $? -eq 0 ]; then
  echo "✅ Build successful!"
  echo "🌐 Starting production server on http://localhost:3011"
  npm run start:prod
else
  echo "❌ Build failed!"
  exit 1
fi
