"use strict";
const test = require("node:test");
const assert = require("node:assert/strict");
const A = require("../static/alteration.js");

const c = (o) => ({ visual: "on", audio: "off", left: 0, right: 0, dark: 0, light: 0, ...o });

test("identity at zero knobs", () => {
  const p = A.plan(c({}));
  assert.equal(p.grade.tone, 0);
  assert.equal(p.overlay.level, 0);
  assert.equal(p.dream.strength, 0);
  assert.equal(p.is_identity, true);
});

test("mood tone is signed (light - dark)/KNOB_MAX, clamped", () => {
  assert.equal(A.plan(c({ light: 4 })).grade.tone, 1);     // full light
  assert.equal(A.plan(c({ dark: 4 })).grade.tone, -1);     // full dark
  assert.equal(A.plan(c({ light: 2 })).grade.tone, 0.5);
});

test("left drives overlay level + intensity; right drives dream + affect", () => {
  const p = A.plan(c({ left: 2, right: 4 }));
  assert.equal(p.overlay.level, 2);
  assert.equal(p.overlay.intensity, 0.5);
  assert.equal(p.dream.strength, 4);
  assert.equal(p.dream.intensity, 1);
  assert.equal(p.affect.strength, 4);
  assert.equal(p.affect.intensity, 1);
  assert.equal(p.is_identity, false);
});

test("renderAudio: off → null, no coupling", () => {
  assert.deepEqual(A.renderAudio("off", "cosmos.mp3", "https://x/"),
    { source: "off", url: null, altitude_coupled: false });
});

test("renderAudio: soundtrack → mediaBase audio url, coupled", () => {
  assert.deepEqual(A.renderAudio("soundtrack", "cosmos.mp3", "https://x/"),
    { source: "soundtrack", url: "https://x/audio/cosmos.mp3", altitude_coupled: true });
  // no scale audio → null url but still coupled
  assert.deepEqual(A.renderAudio("soundtrack", "", "https://x/"),
    { source: "soundtrack", url: null, altitude_coupled: true });
});

test("alteration() composes plan + render with video.shown from visual", () => {
  const r = A.alteration(c({ visual: "off", audio: "soundtrack", left: 1 }), "reef.mp3", "https://x/");
  assert.equal(r.render.video.shown, false);
  assert.equal(r.render.audio.url, "https://x/audio/reef.mp3");
  assert.equal(r.plan.overlay.level, 1);
});
