import assert from "node:assert/strict";
import test from "node:test";
import { buildUserDrawerModel } from "../src/users.js";

test("buildUserDrawerModel surfaces contact and permission details", () => {
	const model = buildUserDrawerModel({
		jellyfin_id: "jf1",
		username: "alex",
		display_name: "alex",
		email: "alex@example.com",
		avatar: "https://example.com/avatar.png",
		avatar_source: "jellyseerr:user",
		email_source: "jellyseerr:user",
		name_source: "jellyfin",
		access_source: "jellyseerr:user",
		contactable: true,
		source_summary:
			"name=jellyfin, email=jellyseerr:user, avatar=jellyseerr:user, access=jellyseerr:user",
		source: "jellyfin, jellyseerr:user",
		jellyseerr_user_id: 7,
		jellyseerr_username: "alex",
		user_type: 3,
		user_type_label: "jellyfin",
		role: "admin",
		permissions: 10,
		permissions_label: "admin, manage_users",
		request_count: 3,
	});

	assert.equal(model.title, "alex");
	assert.equal(model.subtitle, "alex@example.com");
	assert.equal(model.contactState.label, "Contactable");
	assert.equal(model.contactActions[0].label, "Email");
	assert.equal(model.contactActions[0].enabled, false);
	assert.equal(model.permissions.length >= 2, true);
	assert.equal(
		model.identity.some((field) => field.label === "Email source"),
		true,
	);
	assert.equal(model.identity.length >= 4, true);
	assert.equal(model.source.includes("email=jellyseerr:user"), true);
	assert.equal(model.syncStatus.includes("Jellyseerr"), true);
});
