#!/bin/bash
# Tenseal Platform — Shared Hosting Deployment Script
# Run this on the server after uploading/pulling the code
#
# Structure on shared hosting:
#   /home/user/tenseal/          ← Laravel root (private)
#   /home/user/public_html/      ← Symlinked or copy from public/
#
# Usage: bash deploy.sh

set -e

echo "=== Tenseal Platform Deployment ==="

# Install/update dependencies (no dev packages in production)
echo "[1/6] Installing dependencies..."
composer install --no-dev --optimize-autoloader --no-interaction

# Clear and cache config/routes/views
echo "[2/6] Clearing caches..."
php artisan config:clear
php artisan route:clear
php artisan view:clear

echo "[3/6] Caching config and routes..."
php artisan config:cache
php artisan route:cache
php artisan view:cache

# Run migrations
echo "[4/6] Running migrations..."
php artisan migrate --force

# Run seeders (safe — uses firstOrCreate/upsert)
echo "[5/6] Seeding database..."
php artisan db:seed --force

# Storage link
echo "[6/6] Creating storage link..."
php artisan storage:link 2>/dev/null || true

echo ""
echo "=== Deployment complete ==="
echo "Admin login: admin@tenseal.co / TensealAdmin2026!"
echo "Demo login:  demo@tenseal.co / DemoUser2026!"
