package api

import (
	"testing"
	"time"

	"drivervault/apiserver/internal/models"
)

// A car collected new can be fuelled or charged at 0 km on the forecourt; only
// a negative reading is impossible.
func TestZeroKmPassesRecordValidation(t *testing.T) {
	now := time.Now()

	if got := validateFuelEntry(models.FuelEntry{Car: "c1", Date: now, Km: 0, Liters: 40}); got != "" {
		t.Errorf("fuel at 0 km rejected: %s", got)
	}
	if got := validateFuelEntry(models.FuelEntry{Car: "c1", Date: now, Km: -1, Liters: 40}); got == "" {
		t.Error("fuel at -1 km accepted")
	}
	if got := validateChargingSession(models.ChargingSession{Car: "c1", Date: now, Km: 0, Kwh: 12}); got != "" {
		t.Errorf("charge at 0 km rejected: %s", got)
	}
	if got := validateChargingSession(models.ChargingSession{Car: "c1", Date: now, Km: -1, Kwh: 12}); got == "" {
		t.Error("charge at -1 km accepted")
	}
}
