using System;

namespace Valg.EVA.Skanning.Scan.Startup.SelectScannerModel
{
    public class ScannerDefinition
    {
        private int id;

        private static readonly int defaultPriorityId = 9999;

        public static readonly ScannerDefinition Emulate = new ScannerDefinition(9999, "Emulate", defaultPriorityId);
        public static readonly ScannerDefinition Others = new ScannerDefinition(9999, "", 3);

        public ScannerDefinition(string data)
        {
            var dataSplittedToArray = data?.Split(',');
            if (dataSplittedToArray?.Length >= 2)
            {
                int.TryParse(dataSplittedToArray[0], out id);
                if (!string.IsNullOrEmpty(dataSplittedToArray[1]))
                {
                    ModelName = dataSplittedToArray[1].Trim();
                }
            }
        }

        public ScannerDefinition(int id, string modelName, int priorityId)
        {
            this.id = id;
            ModelName = modelName;
            PriorityId = priorityId;
        }

        public override string ToString()
        {
            return ModelName;
        }

        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        public string ModelName { get; set; }
        public int PriorityId { get; set; } = defaultPriorityId;
        public bool IsEmulate => string.Compare(ModelName, "Emulate", StringComparison.InvariantCultureIgnoreCase) == 0;
    }

    public class ScannerDefinitionSeparator : ScannerDefinition
    {
        public static readonly ScannerDefinitionSeparator Separator = new ScannerDefinitionSeparator();
        public ScannerDefinitionSeparator() 
            : base(0, "", 9999)
        {}
    }
}

