using System;
using GHI.Processor;
using SWModules;

namespace HWModules
{
    public static class ConfigurationMemory
    {
        
        public static void Save()
        {
            //Write Key Information
            Configuration.WriteEntry("ProfileNum", BitConverter.GetBytes(SV.ProfileNum+1));
            Configuration.WriteEntry("LastState", BitConverter.GetBytes((ushort)SV.CurrentState));
        }

        public static void Load()
        {
            try
            {
                var profileBytes = Configuration.ReadEntry("ProfileNum");
                var stateBytes = Configuration.ReadEntry("LastState");
                if (profileBytes == null || stateBytes == null)
                {
                    EngrLogger.Comment("Unable to load last profile number mission state");
                    return;
                }
                SV.ProfileNum = BitConverter.ToInt32(profileBytes, 0);
                SV.CurrentState = (CPFStates) BitConverter.ToUInt16(stateBytes, 0);
            }
            catch (ArgumentNullException e)
            {
                EngrLogger.Comment("Unable to load last profile number mission state");
            }
        }
    }
}