using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace TZONE.Model
{
    public class OTA
    {
        public static string packagenumber(string type)
        {
            string xmlPath = string.Format("{0}\\{1}.xml", System.Configuration.ConfigurationManager.AppSettings["ota"], type);
            XDocument root = XDocument.Load(xmlPath);
            var _pn = root.Elements("Bin").First().Attribute("packagenumber").Value;
            return _pn;
        }
        public static string version(string type) {
            string xmlPath = string.Format("{0}\\{1}.xml", System.Configuration.ConfigurationManager.AppSettings["ota"], type);
            XDocument root = XDocument.Load(xmlPath);
            var _v = root.Elements("Bin").First().Attribute("version").Value;
            return _v;
        }
        public static string type(string type)
        {
            string xmlPath = string.Format("{0}\\{1}.xml", System.Configuration.ConfigurationManager.AppSettings["ota"], type);
            XDocument root = XDocument.Load(xmlPath);
            var _t = root.Elements("Bin").First().Attribute("type").Value;
            return _t;
        }

        public static string PackageItemData(string type,string number)
        {
            string xmlPath = string.Format("{0}\\{1}.xml", System.Configuration.ConfigurationManager.AppSettings["ota"], type);
            XDocument root = XDocument.Load(xmlPath);
            var _pid = root.Elements("Bin").Elements("packageitem").Elements("item").First((t) => t.Attribute("itemid").Value == number).Attribute("itemdata").Value;
            return _pid;
        }

        public PackageItem packageitem { get; set; }
        public class PackageItem
        {
            public string itemid { get; set; }
            public string itemdata { get; set; }
        }
       

        /************************************************************************/
        /* Bin                                                                  */
        /************************************************************************/
        public static string packagenumberBin(string type)
        {
            string xmlPath = string.Format("{0}\\{1}.bin.xml", System.Configuration.ConfigurationManager.AppSettings["ota"], type);
            XDocument root = XDocument.Load(xmlPath);
            var _pn = root.Elements("Bin").First().Attribute("packagenumber").Value;
            return _pn;
        }
        public static string versionBin(string type)
        {
            string xmlPath = string.Format("{0}\\{1}.bin.xml", System.Configuration.ConfigurationManager.AppSettings["ota"], type);
            XDocument root = XDocument.Load(xmlPath);
            var _v = root.Elements("Bin").First().Attribute("version").Value;
            return _v;
        }
        public static string PackageItemDataBin(string type, string number)
        {
            string xmlPath = string.Format("{0}\\{1}.bin.xml", System.Configuration.ConfigurationManager.AppSettings["ota"], type);
            XDocument root = XDocument.Load(xmlPath);
            var _pid = root.Elements("Bin").Elements("packageitem").Elements("item").First((t) => t.Attribute("itemid").Value == number).Attribute("itemdata").Value;
            return _pid;
        }

    }

}
