services:
  # Node.js 백엔드
  plm-backend:
    build:
      context: ../../backend-node
      dockerfile: ../docker/prod/backend.Dockerfile # 운영용 Dockerfile
    container_name: pms-backend-prod
    ports:
      - "8080:8080" # 호스트:컨테이너 포트 매핑
    networks:
      - pms-network
    environment:
      - NODE_ENV=production
      - PORT=8080
      - HOST=0.0.0.0 # 모든 인터페이스에서 바인딩
      - DATABASE_URL=${DATABASE_URL}
      - JWT_SECRET=${JWT_SECRET}
      - JWT_EXPIRES_IN=${JWT_EXPIRES_IN:-24h}
      - CORS_ORIGIN=${CORS_ORIGIN:-http://192.168.0.70:5555,http://39.117.244.52:5555,http://localhost:9771}
      - CORS_CREDENTIALS=true
      - LOG_LEVEL=info
      - ENCRYPTION_KEY=${ENCRYPTION_KEY}
      - KMA_API_KEY=${KMA_API_KEY}
      - ITS_API_KEY=${ITS_API_KEY}
      - EXPRESSWAY_API_KEY=${EXPRESSWAY_API_KEY:-}
      - SMART_FACTORY_API_KEY_COMPANY_7=${SMART_FACTORY_API_KEY_COMPANY_7:-}
      - SMART_FACTORY_API_KEY_COMPANY_8=${SMART_FACTORY_API_KEY_COMPANY_8:-}
      - SMART_FACTORY_API_KEY_COMPANY_9=${SMART_FACTORY_API_KEY_COMPANY_9:-}
      - SMART_FACTORY_API_KEY_COMPANY_10=${SMART_FACTORY_API_KEY_COMPANY_10:-}
      - SMART_FACTORY_API_KEY_COMPANY_16=${SMART_FACTORY_API_KEY_COMPANY_16:-}
      # SMTP (견적서/발주서 등 메일 발송)
      - SMTP_HOST=${SMTP_HOST:-erp.rps-korea.com}
      - SMTP_PORT=${SMTP_PORT:-25}
      - SMTP_TLS=${SMTP_TLS:-false}
      - SMTP_SEND_SWITCH=${SMTP_SEND_SWITCH:-Y}
      - SMTP_USER_ERP=${SMTP_USER_ERP:-}
      - SMTP_PW_ERP=${SMTP_PW_ERP:-}
      - SMTP_USER_SALES=${SMTP_USER_SALES:-}
      - SMTP_PW_SALES=${SMTP_PW_SALES:-}
      - SMTP_USER_PURCHASE=${SMTP_USER_PURCHASE:-}
      - SMTP_PW_PURCHASE=${SMTP_PW_PURCHASE:-}
      # Amaranth 전자결재 (수주/견적 등) — wace Constants.AMARANTH_OUT_PROCESS_CODE='RPSPLM_00001' 1:1
      - AMARANTH_OUT_PROCESS_CODE=${AMARANTH_OUT_PROCESS_CODE:-RPSPLM_00001}
      - AMARANTH_OUT_PROCESS_CODE_CONTRACT_ORDER=${AMARANTH_OUT_PROCESS_CODE_CONTRACT_ORDER:-}
      - AMARANTH_OUT_PROCESS_CODE_CONTRACT_ESTIMATE=${AMARANTH_OUT_PROCESS_CODE_CONTRACT_ESTIMATE:-}
      - AMARANTH_FORM_ID_CONTRACT_ORDER=${AMARANTH_FORM_ID_CONTRACT_ORDER:-1161}
      - AMARANTH_FORM_ID_CONTRACT_ESTIMATE=${AMARANTH_FORM_ID_CONTRACT_ESTIMATE:-1162}
      - AMARANTH_COMP_SEQ=${AMARANTH_COMP_SEQ:-1000}
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3001/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

networks:
  pms-network:
    external: true # 외부에서 생성된 네트워크 사용
