version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: auth-app
    restart: always
    environment:
      NODE_ENV: production
      DATABASE_URL: mysql://${DB_USER:-cmlapps_auth}:${DB_PASS:-73ee1708-6d75-4150}@host.docker.internal:${DB_PORT:-3306}/${DB_NAME:-cmlapps_auth}
      BASE_URL: ${BASE_URL:-http://localhost:5004}
      BASE_CRM_URL: ${BASE_CRM_URL:-http://localhost:3000}
      NEXT_PUBLIC_BASE_URL: ${NEXT_PUBLIC_BASE_URL:-http://localhost:5004}
      BASE_ESTIMATES_URL: ${BASE_ESTIMATES_URL:-http://localhost:3001}
      BASE_EXPORTS_URL: ${BASE_EXPORTS_URL:-http://localhost:3002}
      BASE_CRM_API: ${BASE_CRM_API:-http://localhost:3000/api/}
      NEXT_PUBLIC_CRM_API: ${NEXT_PUBLIC_CRM_API:-http://localhost:3000/api/}
      NEXT_PUBLIC_EXPORTS_API: ${NEXT_PUBLIC_EXPORTS_API:-http://localhost:3002/api}
      NEXT_PUBLIC_CML_STORE_BASE_URL: ${NEXT_PUBLIC_CML_STORE_BASE_URL:-http://localhost:3003}
      MEMBERSHIPS_LANDING: ${MEMBERSHIPS_LANDING:-http://localhost:3004}
      CML_STORE_BASE_URL: ${CML_STORE_BASE_URL:-http://localhost:3003}
      NEXTAUTH_SECRET: ${NEXTAUTH_SECRET:-your-secret-key-change-in-production}
      NEXTAUTH_URL: ${NEXTAUTH_URL:-http://localhost:5004}
    ports:
      - "5004:5004"
    volumes:
      - ./src:/app/src
      - ./public:/app/public
    healthcheck:
      test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:5004/api/auth/session"]
      timeout: 10s
      retries: 5
      interval: 30s
