package client

import "testing"

func TestResourcePressureDiskPressure(t *testing.T) {
	if (&ResourcePressure{}).DiskPressure() {
		t.Fatal("nil pct should not pressure")
	}
	low := 5
	if !(&ResourcePressure{DiskFreePct: &low}).DiskPressure() {
		t.Fatal("5% should be disk pressure")
	}
	ok := 15
	if (&ResourcePressure{DiskFreePct: &ok}).DiskPressure() {
		t.Fatal("15% should not pressure")
	}
}

func TestResourcePressureThermalPressure(t *testing.T) {
	if (&ResourcePressure{}).ThermalPressure() {
		t.Fatal("empty should not pressure")
	}
	cpuHot := 90
	if !(&ResourcePressure{CPUTempC: &cpuHot}).ThermalPressure() {
		t.Fatal("cpu > 85 should pressure")
	}
	cpuOK := 80
	gpuHot := 85
	if !(&ResourcePressure{CPUTempC: &cpuOK, GPUTempC: &gpuHot}).ThermalPressure() {
		t.Fatal("gpu > 82 should pressure")
	}
}

func TestResourcePressureThrottled(t *testing.T) {
	if (&ResourcePressure{}).Throttled() {
		t.Fatal("nil throttle false")
	}
	yes := true
	if !(&ResourcePressure{CPUThrottle: &yes}).Throttled() {
		t.Fatal("throttle true")
	}
	no := false
	if (&ResourcePressure{CPUThrottle: &no}).Throttled() {
		t.Fatal("throttle false")
	}
}

func TestResourcePressureJSONOmitempty(t *testing.T) {
	freq := 3000
	r := ResourcePressure{CPUFreqMHz: &freq}
	// smoke: struct tags compile; fields accessible
	if r.CPUFreqMHz == nil || *r.CPUFreqMHz != 3000 {
		t.Fatal("field set")
	}
}
