extends Resource

class_name Substance

@export var formula: StringName
@export var scientific_name: StringName
@export var melting_point: float
@export var boiling_point: float
@export_range(0,1,0.01) var color_influence: float = 0.5
@export var pH: float = 7.0
@export var pHIonicOverrides: Dictionary[Substance,float]
@export var color: Color
@export var pHColor: Gradient
@export var prefer_scientific_name: bool
@export var is_solution: bool

func get_formula() -> StringName:
	return scientific_name if prefer_scientific_name else formula

func get_ph(context: Array[Substance]):
	var overriden_value: float = 0
	var overrides: int = 0
	
	for sub in context:
		if pHIonicOverrides.has(sub):
			overriden_value += pHIonicOverrides[sub]
			overrides += 1
	
	if overrides > 0:
		return overriden_value / overrides
	else:
		return pH

func get_ph_runtime(context: Array[RuntimeSubstanceData]):
	var overriden_value: float = 0
	var overrides: int = 0
	
	for sub in context:
		if pHIonicOverrides.has(sub.substance):
			overriden_value += pHIonicOverrides[sub.substance]
			overrides += 1
	
	if overrides > 0:
		return overriden_value / overrides
	else:
		return pH
