import assert from 'node:assert/strict'
import test from 'node:test'

import {
  createDefaultWorkerHallConfig,
  normalizeWorkerHallConfig,
} from './worker-hall-config-service.js'

test('大厅配置默认展示 50 个订单', () => {
  assert.deepEqual(createDefaultWorkerHallConfig(), {
    maxVisibleOrders: 50,
    categoryMaxVisibleOrders: {},
  })
  assert.deepEqual(normalizeWorkerHallConfig({}), {
    maxVisibleOrders: 50,
    categoryMaxVisibleOrders: {},
  })
})

test('大厅配置只接受 1 到 500 的整数', () => {
  assert.deepEqual(normalizeWorkerHallConfig({ maxVisibleOrders: 88 }), {
    maxVisibleOrders: 88,
    categoryMaxVisibleOrders: {},
  })
  assert.deepEqual(normalizeWorkerHallConfig({ max_visible_orders: 999 }), {
    maxVisibleOrders: 500,
    categoryMaxVisibleOrders: {},
  })
  assert.deepEqual(normalizeWorkerHallConfig({ maxVisibleOrders: 0 }), {
    maxVisibleOrders: 1,
    categoryMaxVisibleOrders: {},
  })
  assert.deepEqual(normalizeWorkerHallConfig({ maxVisibleOrders: 1.5 }), {
    maxVisibleOrders: 50,
    categoryMaxVisibleOrders: {},
  })
  assert.deepEqual(
    normalizeWorkerHallConfig({ categoryMaxVisibleOrders: { '1': 12, '2': 0, '3': 501 } })
      .categoryMaxVisibleOrders,
    { '1': 12 },
  )
})
