services:
  db:
    image: postgres:16-alpine
    container_name: booking_db
    environment:
      POSTGRES_DB: restaurant_booking
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres -d restaurant_booking"]
      interval: 10s
      timeout: 5s
      retries: 5

  backend:
    build:
      context: ./backend
    container_name: booking_backend
    environment:
      DATABASE_URL: postgresql+psycopg2://postgres:postgres@db:5432/restaurant_booking
      BACKEND_CORS_ORIGINS: '["http://localhost:3000"]'
      PUBLIC_BASE_URL: ${PUBLIC_BASE_URL:-http://localhost:8000}
      WHATSAPP_ACCESS_TOKEN: ${WHATSAPP_ACCESS_TOKEN:-}
      WHATSAPP_PHONE_NUMBER_ID: ${WHATSAPP_PHONE_NUMBER_ID:-}
      WHATSAPP_VERIFY_TOKEN: ${WHATSAPP_VERIFY_TOKEN:-}
      WHATSAPP_APP_SECRET: ${WHATSAPP_APP_SECRET:-}
      WHATSAPP_GRAPH_API_VERSION: ${WHATSAPP_GRAPH_API_VERSION:-v21.0}
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "8000:8000"
    volumes:
      - ./backend/app:/app/app

  frontend:
    build:
      context: ./frontend
    container_name: booking_frontend
    environment:
      NEXT_PUBLIC_API_BASE_URL: http://localhost:8000
    depends_on:
      - backend
    ports:
      - "3000:3000"

volumes:
  postgres_data:
