version: '3.8'

services:
  # MySQL Database
  mysql:
    image: mysql:8.0
    container_name: wild-dubai-mysql
    environment:
      MYSQL_ROOT_PASSWORD: rootpassword
      MYSQL_DATABASE: wild_dubai
      MYSQL_USER: app_user
      MYSQL_PASSWORD: app_password
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
      - ./packages/database/schema.sql:/docker-entrypoint-initdb.d/01-schema.sql
      - ./packages/database/seed.sql:/docker-entrypoint-initdb.d/02-seed.sql
    command: --default-authentication-plugin=mysql_native_password
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      timeout: 20s
      retries: 10

  # Redis Cache
  redis:
    image: redis:7-alpine
    container_name: wild-dubai-redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data

  # Next.js Frontend
  web:
    build:
      context: .
      dockerfile: ./apps/web/Dockerfile
    container_name: wild-dubai-web
    environment:
      NODE_ENV: production
      NEXT_PUBLIC_API_URL: http://localhost:3001
      NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: ${STRIPE_PUBLISHABLE_KEY}
    ports:
      - "3000:3000"
    depends_on:
      - api

  # Express API
  api:
    build:
      context: .
      dockerfile: ./apps/api/Dockerfile
    container_name: wild-dubai-api
    environment:
      NODE_ENV: production
      PORT: 3001
      DATABASE_URL: mysql://app_user:app_password@mysql:3306/wild_dubai
      REDIS_URL: redis://redis:6379
      JWT_SECRET: ${JWT_SECRET}
      JWT_REFRESH_SECRET: ${JWT_REFRESH_SECRET}
      STRIPE_SECRET_KEY: ${STRIPE_SECRET_KEY}
      STRIPE_WEBHOOK_SECRET: ${STRIPE_WEBHOOK_SECRET}
      AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
      AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
      S3_BUCKET_NAME: ${S3_BUCKET_NAME}
    ports:
      - "3001:3001"
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_started
    volumes:
      - ./apps/api:/app
      - /app/node_modules

volumes:
  mysql_data:
  redis_data:
