using System;
using System.IO;
using System.Xml.Serialization;
using System.Collections.Generic;

using static Hiperscan.SGS.SgsNt.Protocol.BaseProtocol;

namespace Hiperscan.SGS.Benchtop.FinderSetup
{
    [Serializable]
    public enum SampleHolderType
    {
        None,
        V9F3Prototype,
        V9FinderxWithoutLDW,
        V9FinderxWithLDW
    }

    [Serializable]
    public class SampleHolder
    {
        public SampleHolderType SampleHolderType { get; set; }
        public SamplePositionDetectionData SamplePositionDetection { get; set; }

        public static void Serialize(List<SampleHolder> sample_holders, string file_name)
        {
            using (Stream stream = new FileStream(file_name, FileMode.OpenOrCreate))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(List<SampleHolder>));
                serializer.Serialize(stream, sample_holders);
            }
        }

        public static List<SampleHolder> DeSerialize(string file_name)
        {
            List<SampleHolder> sample_holders = null;
            using (Stream stream = new FileStream(file_name, FileMode.Open, FileAccess.Read))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(List<SampleHolder>));
                sample_holders = (List<SampleHolder>)serializer.Deserialize(stream);
            }

            if (sample_holders == null)
                throw new Exception("Error while deserialization.");


            return sample_holders;
        }

    }
}