using System.IO;
//using System;
//using System.Collections.Generic;
//using System.Linq;
using System.Text;

namespace Nappat.CsCreator
{
    /// <summary>
    /// This is a main class for a C# file creating from added script.
    /// The class manages all processes within creating, contains parameters from a User and store the *.cs file.
    /// </summary>
    public class CsCreator
    {
        #region Private Fields
        #endregion

        /// <summary>
        /// Parameters get from a User Interface.
        /// </summary>
        #region Internal Properties
        internal static string DriverPath { get; set; }
        internal static string ConfigPath { get; set; }
        internal static string ScriptPath { get; set; }
        internal static string TestName { get; set; }
        internal static string DeviceName { get; set; }
        internal static string OutBoardName { get; set; }
        internal static string InBoardName { get; set; }
        internal static string ChannelName { get; set; }
        internal static string OutputPath { get; set; }
        #endregion

        #region Constructors
        public CsCreator(IParamSender ps)
        {
            DriverPath = ps.DriverPath;
            ConfigPath = ps.ConfigPath;
            ScriptPath = ps.ScriptPath;
            TestName = ps.TestName;
            DeviceName = ps.DeviceName;
            OutBoardName = ps.OutBoardName;
            InBoardName = ps.InBoardName;
            ChannelName = ps.ChannelName;
            OutputPath = ps.OutputPath;
        }
        #endregion

        #region Public Methods
        public void CreatCode()
        {
            ScriptParser sp = new ScriptParser(ScriptPath);

            PartWriter pw = new PartWriter(sp.HeaderComments, sp.ScriptBody, sp.ControlSwitchesName, sp.OutputSensorsName, sp.HeadersLength);
            pw.HeaderWriter();
            pw.HeaderCommentsWriter();
            pw.BodyWriter();
            pw.FooterWriter();
            pw.HelpMethodsWriter();

            if (File.Exists(OutputPath + "\\" + TestName + ".cs"))
            {
                File.Delete(OutputPath + "\\" + TestName + ".cs");
            }
            
            File.WriteAllLines(OutputPath + "\\" + TestName + ".cs", PartWriter.FileCreatorList);
        } 
        #endregion       
    }
}
