#!/bin/bash

set -euo pipefail

repo_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd)"
model="$repo_dir/config/dot/quickshell/modules/osd/OsdModel.js"

node - "$model" <<'JS'
const assert = require('node:assert/strict')
const model = require(process.argv[2])

assert.equal(model.iconFor('volume', 0), 'audio-volume-muted-symbolic')
assert.equal(model.iconFor('volume', 0.2), 'audio-volume-low-symbolic')
assert.equal(model.iconFor('volume', 0.5), 'audio-volume-medium-symbolic')
assert.equal(model.iconFor('volume', 0.9), 'audio-volume-high-symbolic')
assert.equal(model.iconFor('microphone-muted', 0.7), 'microphone-sensitivity-muted-symbolic')
assert.equal(model.iconFor('brightness', 0.4), 'display-brightness-symbolic')

assert.deepEqual(
  model.progressState('volume', 140, 100, '', 900),
  {
    kind: 'volume',
    value: 100,
    maximum: 100,
    ratio: 1,
    label: '100%',
    icon: 'audio-volume-high-symbolic',
    duration: 900,
    progress: true
  }
)

assert.deepEqual(
  model.progressState('volume-muted', 43, 100, 'Muted', -50),
  {
    kind: 'volume-muted',
    value: 43,
    maximum: 100,
    ratio: 0.43,
    label: 'Muted',
    icon: 'audio-volume-muted-symbolic',
    duration: 0,
    progress: true
  }
)

assert.deepEqual(
  model.messageState('media-next', 'Glass Beams', 'invalid'),
  {
    kind: 'media-next',
    value: 0,
    maximum: 100,
    ratio: 0,
    label: 'Glass Beams',
    icon: 'media-skip-forward-symbolic',
    duration: 1400,
    progress: false
  }
)

console.log('osd model contract: PASS')
JS
