using System;
using System.IO;
using System.Reflection;
using Hiperscan.Common;
using Hiperscan.Spectroscopy;
using Hiperscan.Spectroscopy.IO;

namespace Hiperscan.ApoIdentCore.SectionManager.Measuring.Simulator
{
    public class SpectrumSimulator
    {

        public static Spectrum  LoadSpectrum()
        {
            string env_value = Environment.GetEnvironmentVariable(Env.ApoIdent.SIMULATE_MEASURING) ?? String.Empty;
            string resource = String.Empty;

            switch(env_value.ToLower())
            {
                case "wasser":
                    resource = "wasser";
                    break;

                case "harnstoff":
                    resource = "harnstoff";
                    break;

                case "thc_type":
                    resource = "thc_type";
                    break;

                case "balance_type":
                    resource = "balance_type";
                    break;

                case "cbd_type":
                    resource = "cbd_type";
                    break;

                case "not_defined":
                    resource = "not_defined";
                    break;

                case "no_trust":
                    resource = "no_trust";
                    break;

                default:
                    return null;

            }

            resource += ".csv";
            resource = "Hiperscan.ApoIdentCore.SectionManager.Measuring.Simulator." + resource;

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource))
            {
                return CSV.Read(stream);
            }
        }

        public static bool SimulationModeOn
        {
            get
            {
                return SpectrumSimulator.LoadSpectrum() != null;
            }
        }
    }
}
