package org.pfaa.chemica.model;


/* A pure substance, including elements and compounds with fixed stoichiometry */
public interface Chemical extends IndustrialMaterial, Vaporizable, Fusible, Soluble {
	public ChemicalConditionProperties getProperties(Condition condition);
	public ChemicalConditionProperties getProperties(Condition condition, State state);
	public Formula getFormula();
	
	default double getEnthalpyOfFusion() {
		Condition cond = this.getFusion().getCondition();
		ChemicalConditionProperties liquid = this.getProperties(cond, State.LIQUID);
		ChemicalConditionProperties solid = this.getProperties(cond, State.SOLID);
		if (solid == null || liquid == null) {
			return Double.NaN;
		}
		return (liquid.entropy - solid.entropy) * cond.temperature;
	}
	
	default Reaction getDissociation() {
		Formula.Part cation = this.getFormula().getFirstPart();
		Formula.Part anion = this.getFormula().getLastPart();
		boolean simpleSalt = cation.ion != null && anion.ion != null && this.getFormula().getParts().size() == 2;
		if (!simpleSalt) {
			return null;
		}
		return Reaction.inWaterOf(1, this, State.SOLID).
				yields(cation.stoichiometry, cation.ion).
				and(anion.stoichiometry, anion.ion);
	}
}

@@ -463,16 +463,22 @@
 on().get
+Liquid
 Conditio
@@ -482,16 +482,16 @@
 tion();%0A
-
 %09%09Chemic
@@ -772,16 +772,405 @@
 e;%0A%09%7D%0A%09%0A
+%09default double getEnthalpyOfVaporization() %7B%0A%09%09Condition cond = this.getVaporization().getGasCondition();%0A%09%09ChemicalConditionProperties liquid = this.getProperties(cond, State.LIQUID);%0A%09%09ChemicalConditionProperties gas = this.getProperties(cond, State.GAS);%0A%09%09if (gas == null %7C%7C liquid == null) %7B%0A%09%09%09return Double.NaN;%0A%09%09%7D%0A%09%09return (gas.entropy - liquid.entropy) * cond.temperature;%0A%09%7D%0A%09%0A
 %09default
@@ -1559,16 +1559,16 @@
 n.ion).%0A
-
 %09%09%09%09and(
@@ -1603,10 +1603,491 @@
 on);%0A%09%7D%0A
+%09%0A%09default double getEnthalpyChange(Condition to) %7B%0A%09%09return this.getEnthalpyChange(Condition.STP, to);%0A%09%7D%0A%09%0A%09default double getEnthalpyChange(Condition from, Condition to) %7B%0A%09%09// TODO: if the enthalpy is NaN, look at adjacent state and add heat of transition, which we know if we know the entropy%0A%09%09ChemicalConditionProperties fromProps = this.getProperties(from);%0A%09%09ChemicalConditionProperties toProps = this.getProperties(to);%0A%09%09return toProps.enthalpy - fromProps.enthalpy;%0A%09%7D%0A
 %7D%0A

add some thermodynamic calculations