using parkMonitor.language;
using parkMonitor.model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace parkMonitor.viewModel.devInfoPanel {
	/// <summary>PC状态Control</summary>
	public class PcStatusPanelVM : ObservableCollection<DevPanelItemVM> {
		public PcStatusPanelVM() {
			cpu = new PcStatusPanelItemVM() { Name = Language.ins.cpu };
			mem = new PcStatusPanelItemVM() { Name = Language.ins.mem };

			Add(cpu);
			Add(mem);
		}

		public PcStatusPanelVM(int? cpuPer, int? memPer):this() {
			setValue(cpuPer, memPer);
		}

		public void setValue(int? cpuPer, int? memPer) {
			cpu.Num = cpuPer;
			mem.Num = memPer;
		}
		
		/// <summary>cpu</summary>
		PcStatusPanelItemVM cpu { get; set; }
		public int? cpuNum { get { return cpu.Num; } set { cpu.Num = value; } }
		
		/// <summary>内存</summary>
		PcStatusPanelItemVM mem { get; set; }
		public int? memNum { get { return mem.Num; } set { mem.Num = value; } }
	}

	/// <summary>PC状态</summary>
	public class PcStatusPanelItemVM : DevPanelItemVM, INotifyPropertyChanged {
		public PcStatusPanelItemVM() {
			Num = null;
		}

		//错误阈值
		int _ErrThreshold = 90;
		public int ErrThreshold {
			get { return _ErrThreshold; }
			set { _ErrThreshold = value; updateColor(); FirePropertyChanged("ErrThreshold"); }
		}

		//警告阈值
		int _WarnThreshold = 80;
		public int WarnThreshold {
			get { return _WarnThreshold; }
			set { _WarnThreshold = value; updateColor(); FirePropertyChanged("WarnThreshold"); }
		}

		//num value
		int? _Num = null;
		public int? Num {
			get { return _Num; }
			set {
				_Num = value;
				if(value == null) {
					Info = "-";
				} else {
					Info = value + "%";
				}
				updateColor();
				FirePropertyChanged("Num");
			}
		}

		private void updateColor() {
			if(_Num == null) {
				ColorByStatus = ComInfoStatus.Offline;
			} else if(_Num >= _ErrThreshold) {
				ColorByStatus = ComInfoStatus.Error;
			} else if(_Num >= _WarnThreshold) {
				ColorByStatus = ComInfoStatus.Warning;
			} else {
				ColorByStatus = ComInfoStatus.Normal;
			}
		}

	}

}
