using System;
using System.Collections.Generic;

namespace DeviceRepair.DataAccess.Data
{
    public class OperationModel
    {
        public int TsSFCUserId { get; set; }

        public Guid GUID { get; set; }

        public string TsSFCUserCode { get; set; }
        
        public string TsSFCUserName { get; set; }

        public string IPAddress { get; set; }

        public string Mac { get; set; }

        public string ComputerName { get; set; }

        public string ProductVersion { get; set; }

        public OperationModel InstanceModel(IDictionary<string, string> apiParameters)
        {
            try
            {
                var parameter = string.Empty;
                var userId = 0;
                if (apiParameters.TryGetValue("OPERATORAUTOID", out parameter))
                    int.TryParse(parameter, out userId);
                TsSFCUserId = userId;

                var gid = Guid.Empty;
                if (apiParameters.TryGetValue("OPERATORGUID", out parameter))
                    Guid.TryParse(parameter, out gid);
                GUID = gid;

                if (apiParameters.TryGetValue("OPERATOR", out parameter))
                    TsSFCUserCode = parameter;
                
                if (apiParameters.TryGetValue("CLIENTIP", out parameter))
                    IPAddress = parameter;
                
                if (apiParameters.TryGetValue("CLIENTMAC", out parameter))
                    Mac = parameter;
                
                if (apiParameters.TryGetValue("CLIENTNAME", out parameter))
                    ComputerName = parameter;
                
                if (apiParameters.TryGetValue("APPVERSION", out parameter))
                    ProductVersion = parameter;

                if (apiParameters.TryGetValue("OPERATORNAME", out parameter))
                    TsSFCUserName = parameter;

                return this;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}