import assert from "node:assert/strict";
import { Plan } from "@prisma/client";
import {
  resolveBurnedSongTitle,
  resolveYouTubeTitle,
  validateYouTubeTitle,
} from "../lib/titles";

function testYouTubeTitleResolution() {
  assert.equal(
    resolveYouTubeTitle({ title: "My Video", songTitle: "Song", artist: "Artist" }, Plan.FREE),
    "My Video",
  );

  assert.equal(
    resolveYouTubeTitle({ title: "", songTitle: "Song", artist: "Artist" }, Plan.FREE),
    "",
  );

  assert.equal(
    resolveYouTubeTitle({ title: "", songTitle: "Song", artist: "Artist" }, Plan.PREMIUM),
    "Artist - Song",
  );

  assert.equal(
    resolveYouTubeTitle({ title: "Custom", songTitle: "Song", artist: "Artist" }, Plan.PREMIUM),
    "Custom",
  );

  assert.equal(
    resolveYouTubeTitle({ title: "", songTitle: "Song", artist: "" }, Plan.PREMIUM),
    "Song",
  );
}

function testBurnedSongTitle() {
  assert.equal(resolveBurnedSongTitle({ songTitle: "Track" }), "Track");
  assert.equal(resolveBurnedSongTitle({ title: "YouTube only" }, "Fallback"), "Fallback");
}

function testValidation() {
  assert.equal(validateYouTubeTitle({ title: "Ok" }, Plan.FREE), null);
  assert.ok(validateYouTubeTitle({ title: "" }, Plan.FREE));
  assert.equal(
    validateYouTubeTitle({ title: "", songTitle: "S", artist: "A" }, Plan.PREMIUM),
    null,
  );
}

testYouTubeTitleResolution();
testBurnedSongTitle();
testValidation();
console.log("titles.test.ts: ok");
