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

import { createDefaultNotificationConfig, normalizeNotificationConfig } from './config-service.js'

test('normalizeNotificationConfig normalizes bark and wpush recipients', () => {
  assert.deepEqual(
    normalizeNotificationConfig({
      enabled: false,
      channels: {
        bark: {
          enabled: true,
          serverUrl: 'https://api.day.app///',
          recipients: [
            {
              name: ' 值班A ',
              deviceKey: ' bark-key ',
              enabled: false,
            },
            {
              name: ' ',
              deviceKey: ' ',
            },
          ],
        },
        wpush: {
          enabled: true,
          recipients: [
            {
              name: ' 值班B ',
              apikey: ' wpush-key ',
            },
            {
              name: '',
              apiKey: '',
            },
          ],
        },
      },
    }),
    {
      enabled: false,
      channels: {
        bark: {
          enabled: true,
          serverUrl: 'https://api.day.app',
          recipients: [
            {
              id: 'bark-key',
              name: '值班A',
              deviceKey: 'bark-key',
              enabled: false,
            },
          ],
        },
        wpush: {
          enabled: true,
          recipients: [
            {
              id: 'wpush-key',
              name: '值班B',
              apiKey: 'wpush-key',
              enabled: true,
            },
          ],
        },
      },
    },
  )
})

test('createDefaultNotificationConfig includes wpush channel', () => {
  assert.deepEqual(createDefaultNotificationConfig(), {
    enabled: true,
    channels: {
      bark: {
        enabled: true,
        serverUrl: 'https://api.day.app',
        recipients: [],
      },
      wpush: {
        enabled: true,
        recipients: [],
      },
    },
  })
})
