package nvidia_bug_report

import (
	"testing"
	"time"

	"git.mchus.pro/mchus/logpile/internal/parser"
)

func TestParseBugReportCollectedAt(t *testing.T) {
	content := `
Start of NVIDIA bug report log file
Date: Fri Dec 12 10:14:49 EST 2025
`

	got, tz, ok := parseBugReportCollectedAt(content)
	if !ok {
		t.Fatalf("expected collected_at to be parsed")
	}
	if tz != "-05:00" {
		t.Fatalf("expected tz offset -05:00, got %q", tz)
	}
	wantUTC := time.Date(2025, 12, 12, 15, 14, 49, 0, time.UTC)
	if !got.UTC().Equal(wantUTC) {
		t.Fatalf("expected %s, got %s", wantUTC, got.UTC())
	}
}

func TestNvidiaBugReportParser_SetsCollectedAtAndTimezone(t *testing.T) {
	p := &Parser{}
	files := []parser.ExtractedFile{
		{
			Path: "nvidia-bug-report-1653925023938.log",
			Content: []byte(`
Start of NVIDIA bug report log file
nvidia-bug-report.sh Version: 34275561
Date: Fri Dec 12 10:14:49 EST 2025
`),
		},
	}

	result, err := p.Parse(files)
	if err != nil {
		t.Fatalf("parse failed: %v", err)
	}

	if result.SourceTimezone != "-05:00" {
		t.Fatalf("expected source timezone -05:00, got %q", result.SourceTimezone)
	}
	wantUTC := time.Date(2025, 12, 12, 15, 14, 49, 0, time.UTC)
	if !result.CollectedAt.Equal(wantUTC) {
		t.Fatalf("expected collected_at %s, got %s", wantUTC, result.CollectedAt)
	}
}
