version: '3.8'

services:
  mysql:
    image: mysql:8
    container_name: handyman-mysql
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-rootpassword}
      MYSQL_DATABASE: ${MYSQL_DATABASE:-handyman}
      MYSQL_USER: ${MYSQL_USER:-handyman}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-handymanpass}
    volumes:
      - mysql_data:/var/lib/mysql
    ports:
      - "3306:3306"
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 10s
      timeout: 5s
      retries: 5

  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: handyman-backend
    restart: unless-stopped
    environment:
      - NODE_ENV=production
      - PORT=5000
      - MYSQL_HOST=mysql
      - MYSQL_PORT=3306
      - MYSQL_USER=${MYSQL_USER:-handyman}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD:-handymanpass}
      - MYSQL_DATABASE=${MYSQL_DATABASE:-handyman}
      - JWT_SECRET=${JWT_SECRET:-your-super-secret-jwt-key-change-in-production}
      - FRONTEND_URL=http://localhost:5173
      - STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY}
      - STRIPE_WEBHOOK_SECRET=${STRIPE_WEBHOOK_SECRET}
    ports:
      - "5000:5000"
    depends_on:
      mysql:
        condition: service_healthy
    volumes:
      - ./backend/uploads:/app/uploads

  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    container_name: handyman-frontend
    restart: unless-stopped
    ports:
      - "5173:80"
    depends_on:
      - backend

volumes:
  mysql_data: