namespace coolprop_wrapper
{
  class Unit
  {
    static string uname(string u) { return SMath.Manager.UnitsManager.GetCurrentUnitName(u); }
    static SMath.Math.Symbolic.MItem unit(string u)
    {
      //return new SMath.Math.Symbolic.MItem(u); // does not have subitems for complex units
      return SMath.Math.Symbolic.Converter.ToMItem(SMath.Manager.Converter.ToTerms(u));
    }
    public static SMath.Math.Symbolic.MItem K { get { return unit(uname("'K")); } }
    public static SMath.Math.Symbolic.MItem Pa { get { return unit(uname("'Pa")); } }
    public static SMath.Math.Symbolic.MItem j_kg { get { return unit(uname("'J") + "/" + uname("'kg")); } }
    public static SMath.Math.Symbolic.MItem mol_m3 { get { return unit(uname("'mol") + "/{" + uname("'m") + "^3}"); } }
    public static SMath.Math.Symbolic.MItem kg_m3 { get { return unit(uname("'kg") + "/{" + uname("'m") + "^3}"); } }
    public static SMath.Math.Symbolic.MItem j_mol { get { return unit(uname("'J") + "/" + uname("'mol")); } }
    public static SMath.Math.Symbolic.MItem j_mol_K { get { return unit(uname("'J") + "/{" + uname("'mol") + "*" + uname("'K") + "}"); } }
    public static SMath.Math.Symbolic.MItem j_kg_K { get { return unit(uname("'J") + "/{" + uname("'kg") + "*" + uname("'K") + "}"); } }

    public static SMath.Math.Symbolic.MItem Find(string param)
    {
      switch (param)
      {
        // Props1 section: values that do not depend on the thermodynamic state
        case "Tcrit":
          return K;
        case "Pcrit":
          return Pa;
        // Props section: values that depend on the thermodynamic state
        case "DMOLAR":
        case "Dmolar":
          return mol_m3;
        case "D":
        case "DMASS":
        case "Dmass":
          return kg_m3;
        case "HMOLAR":
        case "Hmolar":
        case "UMOLAR":
        case "Umolar":
          return j_mol;
        case "H":
        case "HMASS":
        case "Hmass":
          return j_kg;
        case "P":
          return Pa;
        case "SMOLAR":
        case "Smolar":
          return j_mol_K;
        case "S":
        case "SMASS":
        case "Smass":
          return j_kg_K;
        case "T":
          return K;
      }
      return unit("1");
    }
  }
}
