import assert from "node:assert/strict";
import test from "node:test";
import { forecastUnitsWithMultiplier, shouldRequireOwnerApproval, varianceUnits } from "@/lib/operations/logic";

test("owner approval triggers on cost or downtime threshold", () => {
  assert.equal(
    shouldRequireOwnerApproval({
      estimatedCost: 7000,
      expectedDowntimeHours: 1,
      costThreshold: 5000,
      downtimeThresholdHours: 4,
    }),
    true
  );

  assert.equal(
    shouldRequireOwnerApproval({
      estimatedCost: 4000,
      expectedDowntimeHours: 5,
      costThreshold: 5000,
      downtimeThresholdHours: 4,
    }),
    true
  );

  assert.equal(
    shouldRequireOwnerApproval({
      estimatedCost: 4000,
      expectedDowntimeHours: 2,
      costThreshold: 5000,
      downtimeThresholdHours: 4,
    }),
    false
  );
});

test("operations planning helpers compute forecast and variance", () => {
  assert.equal(forecastUnitsWithMultiplier(1000, 1.2), 1200);
  assert.equal(varianceUnits(1000, 1200), 200);
  assert.equal(varianceUnits(1000, 900), -100);
});
