package metricstui

import (
	"strings"
	"testing"
	"time"
)

func TestRenderStatsKeepsRawNumericValues(t *testing.T) {
	t.Parallel()

	series := QueryRangeSeries{
		Label: `tikv_store_size_bytes{type="available"}`,
		Metric: map[string]string{
			"__name__": "tikv_store_size_bytes",
		},
		Samples: []QueryRangeSample{
			{
				Timestamp: time.Unix(1712123000, 0).UTC(),
				Value:     3141477468871,
			},
			{
				Timestamp: time.Unix(1712123060, 0).UTC(),
				Value:     3141477468871,
			},
		},
	}

	got := renderStats(series, 120)
	if !strings.Contains(got, "3141477468871.0000") {
		t.Fatalf("renderStats() = %q, want raw numeric value", got)
	}
	if strings.Contains(got, "TiB") || strings.Contains(got, "GiB") || strings.Contains(got, "MiB") {
		t.Fatalf("renderStats() = %q, want no inferred unit", got)
	}
}

func TestRenderChartUsesLineDrawingAndTimeLabels(t *testing.T) {
	t.Parallel()

	series := QueryRangeSeries{
		Label: `tikv_store_size_bytes{type="available"}`,
		Metric: map[string]string{
			"__name__": "tikv_store_size_bytes",
		},
		Samples: []QueryRangeSample{
			{
				Timestamp: time.Unix(1712123000, 0).UTC(),
				Value:     3141477468871,
			},
			{
				Timestamp: time.Unix(1712123060, 0).UTC(),
				Value:     3141477468871,
			},
		},
	}

	got := renderChart(series, 100, 14)
	if !strings.Contains(got, "─") {
		t.Fatalf("renderChart() = %q, want visible line drawing", got)
	}
	if !strings.Contains(got, ":") {
		t.Fatalf("renderChart() = %q, want time-of-day labels on X axis", got)
	}
	if !strings.Contains(got, "*") {
		t.Fatalf("renderChart() = %q, want visible data markers", got)
	}
}
