using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MeterVision.db
{
    public class VPatchStation : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }


        public string PatchId{ get; set;}

        public string StationId { get; set; }
       
        public int TotalCount { get; set; }

        private int _errorCount;
        public int ErrorCount
        {
            get => _errorCount;
            set
            {
                if(_errorCount != value)
                {
                    _errorCount = value;
                    OnPropertyChanged(nameof(ErrorCount));
                    OnPropertyChanged(nameof(RunCount));
                    OnPropertyChanged(nameof(TotalRunRateColor));
                    OnPropertyChanged(nameof(InvalidRateName));
                    OnPropertyChanged(nameof(EqualRateName));
                    OnPropertyChanged(nameof(ErrorRateName));
                }
            }
        }

        private int _equalCount;
        public int EqualCount
        {
            get => _equalCount;
            set
            {
                if (_equalCount != value)
                {
                    _equalCount = value;
                    OnPropertyChanged(nameof(EqualCount));
                    OnPropertyChanged(nameof(RunCount));
                    OnPropertyChanged(nameof(TotalRunRateColor));
                    OnPropertyChanged(nameof(InvalidRateName));
                    OnPropertyChanged(nameof(EqualRateName));
                    OnPropertyChanged(nameof(ErrorRateName));
                }
            }
        }


        private int _invalidCount;
        public int InvalidCount
        {
            get => _invalidCount;
            set
            {
                if (_invalidCount != value)
                {
                    _invalidCount = value;
                    OnPropertyChanged(nameof(InvalidCount));
                    OnPropertyChanged(nameof(RunCount));
                    OnPropertyChanged(nameof(TotalRunRateColor));
                    OnPropertyChanged(nameof(InvalidRateName));
                    OnPropertyChanged(nameof(EqualRateName));
                    OnPropertyChanged(nameof(ErrorRateName));
                }
            }
        }

        public int Index { get; set; }

        //总数
        public int RunCount => (EqualCount + InvalidCount + ErrorCount);

        private float EqualRate => RunCount > 0 ? (float)EqualCount / RunCount : 0.0f;
        public string EqualRateName => $"{EqualCount} ({EqualRate.ToString("P1")})";

        private float ErrorRate => RunCount > 0 ? (float)ErrorCount / RunCount : 0.0f;
        public string ErrorRateName => $"{ErrorCount} ({ErrorRate.ToString("P1")})";

        private float InvalidRate => RunCount > 0 ? (float)InvalidCount / RunCount : 0.0f;
        public string InvalidRateName => $"{InvalidCount} ({InvalidRate.ToString("P1")})";

        public string TotalRunRateColor => (TotalCount == RunCount) ? "#1E90FF" : "#000000";


        public string StationIdName
        {            
            get
            {
                if (StationId == "")
                {
                    return "全部站点";
                }
                return StationId;
            }
        }

        public VPatchStation()
        {

        }
        //-------------------------------------------------------
    }
}
