# File: backend/docker-compose.yml
# DMS Container v0_8_0 แยก service/ lcbp3-backend
x-restart: &restart_policy
  restart: unless-stopped

x-logging: &default_logging
  logging:
    driver: "json-file"
    options:
      max-size: "10m"
      max-file: "5"
volumes:
  backend_node_modules:
services:
  backend:
    <<: [*restart_policy, *default_logging]
    image: dms-backend:dev
    # pull_policy: never  # <-- FINAL FIX ADDED HERE
    container_name: dms_backend
    stdin_open: true
    tty: true
    #user: "node"
    user: "1000:1000"
    working_dir: /app
    deploy:
      resources:
        limits:
          cpus: "2.0"
          memory: 1G
        reservations:
          cpus: "0.25"
          memory: 256M
    environment:
      TZ: "Asia/Bangkok"
      CHOKIDAR_USEPOLLING: "1"
      CHOKIDAR_INTERVAL: "300"
      WATCHPACK_POLLING: "true"
      # NODE_ENV: "production"
      NODE_ENV: "development"
      PORT: "3001"
      DB_HOST: "mariadb"
      DB_PORT: "3306"
      DB_USER: "center"
      DB_PASSWORD: "Center#2025"
      DB_NAME: "dms"
      JWT_SECRET: "9a6d8705a6695ab9bae4ca1cd46c72a6379aa72404b96e2c5b59af881bb55c639dd583afdce5a885c68e188da55ce6dbc1fb4aa9cd4055ceb51507e56204e4ca"
      JWT_ACCESS_SECRET: "9a6d8705a6695ab9bae4ca1cd46c72a6379aa72404b96e2c5b59af881bb55c639dd583afdce5a885c68e188da55ce6dbc1fb4aa9cd4055ceb51507e56204e4ca"
      JWT_REFRESH_SECRET: "743e798bb10d6aba168bf68fc3cf8eff103c18bd34f1957a3906dc87987c0df139ab72498f2fe20d6c4c580f044ccba7d7bfa4393ee6035b73ba038f28d7480c"
      ACCESS_TTL_MS: "900000"
      REFRESH_TTL_MS: "604800000"
      JWT_EXPIRES_IN: "12h"
      PASSWORD_SALT_ROUNDS: "10"
      FRONTEND_ORIGIN: "https://lcbp3.np-dms.work"
      CORS_ORIGINS: "https://backend.np-dms.work,http://localhost:3000,http://127.0.0.1:3000,https://lcbp3.np-dms.work"
      COOKIE_DOMAIN: ".np-dms.work"
      RATE_LIMIT_WINDOW_MS: "900000"
      RATE_LIMIT_MAX: "200"
      BACKEND_LOG_DIR: "/app/logs"
    networks:
      lcbp3: {}
    volumes:
      - "/share/Container/dms/backend/src:/app/src:rw"
      # - "/share/Container/dms/backend/package.json:/app/package.json"
      # - "/share/Container/dms/backend/package-lock.json:/app/package-lock.json"
      - "/share/dms-data:/share/dms-data:rw"
      - "/share/Container/dms/logs/backend:/app/logs:rw"
      # - "/share/Container/dms/backend/node_modules:/app/node_modules"
      - "backend_node_modules:/app/node_modules"
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://127.0.0.1:3001/health"]
      interval: 10s
      timeout: 5s
      retries: 30

networks:
  lcbp3:
    external: true
