import { describe, expect, test } from "bun:test"

import type { NotificationItem } from "@shared/store/notifications"

import { getNotificationPresentation } from "./presentation"

function buildNotification(
	overrides: Partial<NotificationItem> = {},
): NotificationItem {
	return {
		event: "task_update",
		notification_id: "notification-1",
		job_id: "job-1",
		project_id: "project-1",
		job_type: "TRANSCRIPTION_GENERATE",
		status: "DONE",
		progress_pct: 100,
		message: "Завершено",
		title: "Задача завершена",
		created_at: "2026-04-05T12:00:00.000Z",
		is_read: false,
		...overrides,
	}
}

describe("getNotificationPresentation", () => {
	test("uses the task type as the notification title and moves status into secondary text", () => {
		expect(getNotificationPresentation(buildNotification())).toEqual({
			title: "Транскрипция",
			statusText: "Завершено",
			statusVariant: "success",
			detailText: null,
		})
	})

	test("maps silence apply notifications to the operation title instead of backend status title", () => {
		expect(
			getNotificationPresentation(
				buildNotification({
					job_type: "SILENCE_APPLY",
					title: "Задача завершена",
					message: "Завершено",
				}),
			),
		).toEqual({
			title: "Применение вырезок",
			statusText: "Завершено",
			statusVariant: "success",
			detailText: null,
		})
	})

	test("keeps detailed progress text when it carries more information than the status", () => {
		expect(
			getNotificationPresentation(
				buildNotification({
					status: "RUNNING",
					message: "Транскрибирование (whisper)",
				}),
			),
		).toEqual({
			title: "Транскрипция",
			statusText: "Выполняется",
			statusVariant: "info",
			detailText: "Транскрибирование (whisper)",
		})
	})

	test("maps failed notifications to a danger badge", () => {
		expect(
			getNotificationPresentation(
				buildNotification({
					status: "FAILED",
					message: "Ошибка",
				}),
			),
		).toEqual({
			title: "Транскрипция",
			statusText: "Ошибка",
			statusVariant: "danger",
			detailText: null,
		})
	})
})
