#!/bin/bash

# ============================================================
# @project   biiproject
# @author    Andika Debi Putra
# @email     andikadebiputra@gmail.com
# @website   https://biiproject.com
# @copyright Copyright (c) 2026 Andika Debi Putra
# @license   Proprietary - All Rights Reserved
# @version   1.0.0
# @created   2026-05-01
# ============================================================

# Exit on error
set -e

echo "🚀 Starting biiproject deployment..."

# Enter maintenance mode
php artisan down || true

# Update codebase
# git pull origin main

# Install dependencies
composer install --no-dev --optimize-autoloader

# Clear/Warmup Cache
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cache

# Run Database Migrations
php artisan migrate --force

# Install/Build Assets
npm install
npm run build

# Run Performance Optimizations
php artisan system:optimize

# Restart Background Services
php artisan queue:restart
# If using Horizon
php artisan horizon:terminate || true

# Generate Documentation (Optional)
php artisan l5-swagger:generate

# Exit maintenance mode
php artisan up

# Run Health Check
php artisan system:check

echo "✅ Deployment finished successfully!"
