package quantity

import "base:intrinsics"

//----- Liters Per Minute ----------------------------------
Liters_Per_Minute :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
	v: V,
}

@(private = "file")
liters_per_minute_to_gallons_per_minute :: #force_inline proc "contextless" (
	liters_per_minute: Liters_Per_Minute($V),
) -> Gallons_Per_Minute(V) where intrinsics.type_is_float(V) {
	return Gallons_Per_Minute(V){liters_per_minute.v / LITERS_PER_GALLON}
}

//----- Gallons Per Minute ----------------------------------
Gallons_Per_Minute :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
	v: V,
}

@(private = "file")
gallons_per_minute_to_liters_per_minute :: #force_inline proc "contextless" (
	gallons_per_minute: Gallons_Per_Minute($V),
) -> Liters_Per_Minute(V) where intrinsics.type_is_float(V) {
	return Liters_Per_Minute(V){gallons_per_minute.v * LITERS_PER_GALLON}
}

// ---------------------------------------------------------------------------------------------------------------------
// ----- Conversion Overloads ------------------------
// ---------------------------------------------------------------------------------------------------------------------
to_liters_per_minute :: proc {
	gallons_per_minute_to_liters_per_minute,
}

to_gallons_per_minute :: proc {
	liters_per_minute_to_gallons_per_minute,
}

// ---------------------------------------------------------------------------------------------------------------------
// ----- Tests ------------------------
// ---------------------------------------------------------------------------------------------------------------------
import "core:testing"

@(test)
test_gallons_per_minute_to_liters_per_minute :: proc(t: ^testing.T) {
	gallons_per_minute := Gallons_Per_Minute(f32){1}
	liters_per_minute := to_liters_per_minute(gallons_per_minute)

	testing.expect(t, liters_per_minute.v > 3.78 && liters_per_minute.v < 3.79)
}

@(test)
test_liters_per_minute_to_gallons_per_minute :: proc(t: ^testing.T) {
	liters_per_minute := Liters_Per_Minute(f32){3.785411784}
	gallons_per_minute := to_gallons_per_minute(liters_per_minute)

	testing.expect(t, gallons_per_minute.v > 0.99 && gallons_per_minute.v < 1.01)
}
