#!/bin/bash

# Docker validation script
set -e

echo "🔍 Validating Docker configuration..."

# Check if Docker is available
if ! command -v docker &> /dev/null; then
    echo "❌ Docker is not installed or not in PATH"
    echo "Please install Docker Desktop and enable WSL 2 integration"
    exit 1
fi

# Check if docker-compose is available
if ! command -v docker-compose &> /dev/null; then
    echo "❌ Docker Compose is not installed or not in PATH"
    exit 1
fi

echo "✅ Docker and Docker Compose are available"

# Validate Dockerfile syntax
echo "🔍 Validating Dockerfile..."
if docker build --dry-run . > /dev/null 2>&1; then
    echo "✅ Dockerfile syntax is valid"
else
    echo "❌ Dockerfile syntax is invalid"
    exit 1
fi

# Validate docker-compose.yml
echo "🔍 Validating docker-compose.yml..."
if docker-compose config > /dev/null 2>&1; then
    echo "✅ docker-compose.yml is valid"
else
    echo "❌ docker-compose.yml is invalid"
    exit 1
fi

# Validate docker-compose.dev.yml
echo "🔍 Validating docker-compose.dev.yml..."
if docker-compose -f docker-compose.dev.yml config > /dev/null 2>&1; then
    echo "✅ docker-compose.dev.yml is valid"
else
    echo "❌ docker-compose.dev.yml is invalid"
    exit 1
fi

echo "✅ All Docker configurations are valid!"
echo ""
echo "🚀 Ready to build and run:"
echo "  make build    # Build Docker image"
echo "  make up       # Start services"
echo "  make logs     # View logs" 