using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;

namespace Packing.lib
{
    public class WorkingState
    {
        private WorkingState()
        {
        }

        public object this[string propertyName]
        {
            get
            {
                // probably faster without reflection:
                // like:  return Properties.Settings.Default.PropertyValues[propertyName] 
                // instead of the following
                Type myType = typeof(WorkingState);
                PropertyInfo myPropInfo = myType.GetProperty(propertyName);
                return myPropInfo.GetValue(this, null);
            }
            set
            {
                Type myType = typeof(WorkingState);
                PropertyInfo myPropInfo = myType.GetProperty(propertyName);
                myPropInfo.SetValue(this, value, null);
            }
        }

        [JsonConstructor]
        public WorkingState(
            string step
            , string pallet_no
            , string scan_count
            , string leaktest_code
            , string packing_time
            , string serial_no
            , string part_name
            , string part_code
            , string abbreviation
            , string part_no
            )
        {
            this.step = step;
            this.pallet_no = pallet_no;
            this.scan_count = scan_count;
            this.leaktest_code = leaktest_code;
            this.packing_time = packing_time;
            this.serial_no = serial_no;
            this.part_name = part_name;
            this.part_code = part_code;
            this.abbreviation = abbreviation;
            this.part_no = part_no;
        }

        public static WorkingState Load(string filename)
        {
            WorkingState working = new WorkingState();
            working = (WorkingState) JsonFileReader.Read<WorkingState>(filename);
            return working;
        }
        public static void Save(WorkingState working, string filename)
        {
            JsonFileReader.Save<WorkingState>(working, filename);
        }

        public string step { get; set; }
        public string pallet_no { get; set; }
        public string scan_count { get; set; }
        public string leaktest_code { get; set; }
        public string packing_time { get; set; }
        public string serial_no { get; set; }
        public string part_name { get; set; }
        public string part_code { get; set; }
        public string abbreviation { get; set; }
        public string part_no { get; set; }
    }
}
