version: "3.8"

services:
  # Node.js 백엔드
  backend:
    build:
      context: ../../backend-node
      dockerfile: ../docker/deploy/backend.Dockerfile
    container_name: pms-backend-prod
    restart: always
    environment:
      NODE_ENV: production
      PORT: "3001"
      HOST: 0.0.0.0
      DATABASE_URL: ${DATABASE_URL}
      JWT_SECRET: ${JWT_SECRET}
      JWT_EXPIRES_IN: ${JWT_EXPIRES_IN:-24h}
      CORS_ORIGIN: ${CORS_ORIGIN:-https://v1.vexplor.com,https://api.vexplor.com}
      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_10: ${SMART_FACTORY_API_KEY_COMPANY_10:-}
      SMART_FACTORY_API_KEY_COMPANY_9: ${SMART_FACTORY_API_KEY_COMPANY_9:-}
      # 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}
    volumes:
      - backend_uploads:/app/uploads
      - backend_data:/app/data
    labels:
      - traefik.enable=true
      - traefik.http.routers.backend.rule=Host(`api.vexplor.com`)
      - traefik.http.routers.backend.entrypoints=websecure,web
      - traefik.http.routers.backend.tls=true
      - traefik.http.routers.backend.tls.certresolver=le
      - traefik.http.services.backend.loadbalancer.server.port=3001

  # Next.js 프론트엔드
  frontend:
    build:
      context: ../../frontend
      dockerfile: ../docker/deploy/frontend.Dockerfile
      args:
        - NEXT_PUBLIC_API_URL=https://api.vexplor.com/api
        - SERVER_API_URL=http://backend:3001
    container_name: pms-frontend-prod
    restart: always
    environment:
      NODE_ENV: production
      NEXT_PUBLIC_API_URL: https://api.vexplor.com/api
      SERVER_API_URL: "http://backend:3001"
      NEXT_TELEMETRY_DISABLED: "1"
      PORT: "3000"
      HOSTNAME: 0.0.0.0
    volumes:
      - frontend_data:/app/data
    labels:
      - traefik.enable=true
      - traefik.http.routers.frontend.rule=Host(`v1.vexplor.com`)
      - traefik.http.routers.frontend.entrypoints=websecure,web
      - traefik.http.routers.frontend.tls=true
      - traefik.http.routers.frontend.tls.certresolver=le
      - traefik.http.services.frontend.loadbalancer.server.port=3000

volumes:
  backend_uploads:
    driver: local
  backend_data:
    driver: local
  frontend_data:
    driver: local

networks:
  default:
    name: toktork_server_default
    external: true
