using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;  //tridy StreamWriter, StreamReader, File
namespace USB_SMB
{
    class smb
    {
        //------------ private -----------------
        #region private_region
        private UInt16 no;              //number in one file - private own counter
        private float temperature;
        private string chemistry;      
        private string name;            //device name
        private string manufacturer;    
        private UInt16 number;          //serial number of device
        private float descapacity;      //designed capacity - new battery
        private float remcapacity;      //remaining capacity - state right now
        private float fullcapacity;     //full charge capacity - charged right now, up to max
        private UInt16 cycles;          // charging cycles
        private float voltage;          //actual voltage
        private float desvoltage;       //designed voltage
        
        #endregion
        //------------ public ------------------
        #region public_region
        public UInt16 Day;             //day of manufacture
        public UInt16 Month;           //month of manufacture
        public UInt16 Year;            //year of manufact


        public UInt16 No
        {
            get
            {
                return no;
            }
            set
            {
                no = value;
            }
        }

        public float Temperature
        {
            get
            {
                return temperature;
            }
            set
            {
                temperature = (value - 2732) / 10;
                if (temperature < (-20))
                    temperature = 0;
            }
        }
        public string Chemistry
        {
            get
            {
                return chemistry;
            }
            set
            {
                chemistry = value;
            }
        }
        public string Name
        {
            get {
                return name;
            }
            set {
                name = value;
            }
        }
        public string Manufacturer
        {
            get
            {
                return manufacturer;
            }
            set
            {
                manufacturer = value;
            }
        }
        public UInt16 S_Number
        {
            get
            {
                return number;
            }
            set
            {
                number = value;
            }
        }
        public UInt16 Manufacture_date
        {
            set
            {
                Year = value;
                Day = Convert.ToUInt16(Year & 0x1F);
                Month = Convert.ToUInt16((Year >> 5) & 0x0F);
                Year = Convert.ToUInt16(((Year>>9)&0x7F)+1980);
            }
        }
        
        public float Designed_Capacity      // unit: Wh
        {
            get
            {
                return descapacity;
            }
            set
            {
                descapacity = value/100;
            }
        }
        public float Remaining_Capacity  //unit: Wh
        {
            get
            {
                return remcapacity;
            }
            set
            {
                remcapacity = value/100;
            }
        }
        public float Full_Capacity      // Wh
        {
            get
            {
                return fullcapacity;
            }
            set
            {
                fullcapacity = value/100;
            }
        }
        public UInt16 Cycle_Count
        {
            get
            {
                return cycles;
            }
            set
            {
                cycles = value;
            }

        }
        public float Voltage
        {
            get {
                return voltage;
            }
            set
            {
                voltage = value/1000;
            }
        }
        public float Designed_Voltage
        {
            get
            {
                return desvoltage;
            }
            set
            {
                desvoltage = value/1000;
            }
        }

        public void Save_to_txt(List<smb> all_batteries,string txt_path)
        {
            int i = 0;
            List<string> alllines = new List<string>();
            for (i = 0; i < all_batteries.Count; i++)
            {
                alllines.Add(all_batteries[i].No.ToString()+". ");
                alllines.Add("Serial number: "+all_batteries[i].S_Number.ToString());
                alllines.Add("Manufacturer: "+all_batteries[i].Manufacturer);
                alllines.Add("Name: "+all_batteries[i].Name);
                alllines.Add("Chemistry: "+all_batteries[i].Chemistry);
                alllines.Add("Manufacture Date: " + all_batteries[i].Day.ToString()+"." + all_batteries[i].Month.ToString()+"." + all_batteries[i].Year.ToString());
                alllines.Add("Designed Capacity: "+all_batteries[i].Designed_Capacity.ToString()+" Wh");
                alllines.Add("Designed Voltage: "+all_batteries[i].Designed_Voltage.ToString()+" V");
                alllines.Add("Cycle Count: " + all_batteries[i].Cycle_Count.ToString());
                alllines.Add("Full Capacity: " + all_batteries[i].Full_Capacity.ToString()+" Wh");
                alllines.Add("Actual Capacity: " + all_batteries[i].Remaining_Capacity.ToString() + " Wh");
                alllines.Add("Actual Voltage: " + all_batteries[i].Voltage.ToString() + " V");
                alllines.Add("----------------------");
            }
            
           
            File.WriteAllLines(txt_path, alllines.ToArray());
            
        }

        #endregion


    }
}
