#!/bin/bash
set -e

echo "=== SA DL Decoder Setup ==="
echo ""

echo "Step 1: Building Docker image..."
docker compose build

echo ""
echo "Step 2: Generating app key..."
docker compose run --rm app php artisan key:generate

echo ""
echo "Step 3: Setting permissions..."
docker compose run --rm -u root app bash -c "
  chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache && \
  chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache
"

echo ""
echo "Step 4: Starting containers..."
docker compose up -d

echo ""
echo "=== Setup complete! ==="
echo ""
echo "API endpoint:   http://localhost:8080/api/decode-licence"
echo "API docs:       http://localhost:8080/docs"
echo ""
echo "Android emulator base URL: http://10.0.2.2:8080"
echo "Physical device base URL:  http://<your-lan-ip>:8080"
echo ""
