extends Resource

class_name Reaction

@export var input_substances: Array[ReactionSubstance]
@export var output_substances: Array[ReactionSubstance]
@export var reaction_temperature: float = -1

func input_substances_dict() -> Dictionary[StringName, ReactionSubstance]:
	var result: Dictionary[StringName, ReactionSubstance] = {}
	
	for el in input_substances:
		result[el.substance.scientific_name] = el
	
	return result

func formula() -> String:
	var result = ""
	
	for i in range(len(input_substances)):
		result += str(input_substances[i].coefficient) + input_substances[i].substance.get_formula()
		if i != len(input_substances)-1:
			result += " + "
	
	result += " = "
	
	for i in range(len(output_substances)):
		result += str(output_substances[i].coefficient) + output_substances[i].substance.get_formula()
		if i != len(output_substances)-1:
			result += " + "
	
	return result
