package types

import (
	"testing"

	scoutDomain "apps/backend/internal/module/scout/domain"
)

func TestScoutRunFromDomainPreservesCountersAndUnixNano(t *testing.T) {
	created := int64(1_700_000_000_123_456_789)
	run := &scoutDomain.Run{
		ID: "run-1", JobID: "job-1", ThemeKey: "theme|one", ThemeLabel: "One",
		Intent: "one", Mode: scoutDomain.ModeTheme, BrandID: "brand-1", TargetCount: 8,
		Status: scoutDomain.RunSucceeded, SearchedCount: 22, DuplicateCount: 4,
		IrrelevantCount: 3, EligibleCount: 8, PendingCount: 5, ShortfallCount: 0,
		ShortfallReasons: []string{scoutDomain.ShortfallDuplicateExhausted}, CreatedAt: created,
		StartedAt: created + 1, CompletedAt: created + 2, Error: "",
	}
	out := ScoutRunFromDomain(run)
	if out.Id != run.ID || out.JobId != run.JobID || out.CreatedAt != created || out.StartedAt != created+1 || out.CompletedAt != created+2 {
		t.Fatalf("run identity/time changed: %+v", out)
	}
	if out.SearchedCount != 22 || out.DuplicateCount != 4 || out.IrrelevantCount != 3 || out.EligibleCount != 8 || out.PendingCount != 5 {
		t.Fatalf("run counters changed: %+v", out)
	}
	if len(out.ShortfallReasons) != 1 || out.ShortfallReasons[0] != scoutDomain.ShortfallDuplicateExhausted {
		t.Fatalf("shortfall reasons changed: %+v", out.ShortfallReasons)
	}
}

func TestScoutPostFromDomainIncludesRunID(t *testing.T) {
	out := ScoutPostFromDomain(&scoutDomain.Post{ID: "post-1", RunID: "run-1", CreatedAt: 1})
	if out.RunId != "run-1" {
		t.Fatalf("run id not mapped: %+v", out)
	}
}
