#!/usr/bin/env bash
set -euo pipefail

cd "$(dirname "$0")/.."

echo "==> Installing PHP dependencies"
composer install --no-dev --optimize-autoloader

echo "==> Running migrations"
php artisan migrate --force

echo "==> Ensuring storage symlink"
php artisan storage:ensure-link

echo "==> Building frontend assets"
npm ci
npm run build

echo "==> Caching config/routes/views"
php artisan config:cache
php artisan route:cache
php artisan view:cache

echo "==> Deploy complete"
echo "    Ensure APP_URL in .env matches your live domain (https://...)"
echo "    Ensure storage/app/public/meals/ contains uploaded images"
