services:
  backend:
    container_name: lean101-clients-backend
    build:
      context: .
      dockerfile: backend/Dockerfile
    restart: unless-stopped
    environment:
      APP_NAME: ${APP_NAME:-Lean 101 Clients API}
      DATABASE_URL: ${DATABASE_URL:-sqlite:////data/data_entry_app.db}
      CLIENT_NAME: ${CLIENT_NAME:-Hunter Premium Produce}
      CLIENT_EMAIL: ${CLIENT_EMAIL:-operator@example.com}
      CLIENT_PASSWORD: ${CLIENT_PASSWORD:-changeme}
      CLIENT_TENANT_ID: ${CLIENT_TENANT_ID:-hunter-premium-produce}
      ADMIN_NAME: ${ADMIN_NAME:-Lean 101}
      ADMIN_EMAIL: ${ADMIN_EMAIL:-admin@lean101.local}
      ADMIN_PASSWORD: ${ADMIN_PASSWORD:-lean101-admin}
      AUTH_SECRET: ${AUTH_SECRET:-change-me-in-production}
      CORS_ALLOW_ORIGINS: ${CORS_ALLOW_ORIGINS:-https://clients.lean-101.com.au}
    volumes:
      - clients_app_data:/data
    healthcheck:
      test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/health')"]
      interval: 30s
      timeout: 5s
      retries: 5
      start_period: 20s

  frontend:
    container_name: lean101-clients-frontend
    build:
      context: .
      dockerfile: frontend/Dockerfile
    restart: unless-stopped
    environment:
      ORIGIN: ${ORIGIN:-https://clients.lean-101.com.au}
      PORT: 3000
      HOST: 0.0.0.0
      PUBLIC_API_BASE_URL: ${PUBLIC_API_BASE_URL:-https://clients.lean-101.com.au}
      INTERNAL_API_BASE_URL: ${INTERNAL_API_BASE_URL:-http://backend:8000}
      PUBLIC_API_PORT: ${PUBLIC_API_PORT:-8000}
      PUBLIC_MIX_CALCULATOR_SESSION_HISTORY: ${PUBLIC_MIX_CALCULATOR_SESSION_HISTORY:-false}
      PUBLIC_MIX_CALCULATOR_SESSION_SAVE: ${PUBLIC_MIX_CALCULATOR_SESSION_SAVE:-false}
    depends_on:
      backend:
        condition: service_healthy

  nginx:
    container_name: lean101-clients
    image: nginx:1.27-alpine
    restart: unless-stopped
    depends_on:
      frontend:
        condition: service_started
      backend:
        condition: service_healthy
    ports:
      - "${CLIENTS_APP_PORT:-8081}:80"
    volumes:
      - ./deploy/nginx/clients.lean-101.conf:/etc/nginx/conf.d/default.conf:ro

volumes:
  clients_app_data:
