using System;
using Valg.EVA.Skanning.Contracts.CommonEnums;
using Valg.EVA.Skanning.Resources;
using Valg.EVA.Skanning.Resources.Language;
using ReactiveUI;

namespace Valg.EVA.Skanning.JobManagement.Startup.Data
{
    public class CountingModel : ReactiveObject, IUpdatable<CountingModel, int>
    {
        private int id;
        public int Id
        {
            get { return id; }
            set { this.RaiseAndSetIfChanged(ref id, value); }
        }

        public string Name
        {
            get
            {
                return string.Format(
                    "{0} {1}",
                    LanguageString.ResourceManager.GetEnumString(CountingType),
                    CountNumber);
            }
        }
       
        private int countNumber;
        public int CountNumber
        {
            get { return countNumber; }
            set { this.RaiseAndSetIfChanged(ref countNumber, value); }
        }
        
        private CountingType countingType;
        public CountingType CountingType
        {
            get { return countingType; }
            set { this.RaiseAndSetIfChanged(ref countingType, value); }
        }
        
        private CountingState countingState;
        public CountingState CountingState
        {
            get { return countingState; }
            set { this.RaiseAndSetIfChanged(ref countingState, value); }
        }
        
        private string uniqueId;
        public string UniqueId
        {
            get { return uniqueId; }
            set { this.RaiseAndSetIfChanged(ref uniqueId, value); }
        }
        
        private string contestId;
        public string ContestId
        {
            get { return contestId; }
            set { this.RaiseAndSetIfChanged(ref contestId, value); }
        }
        
        private string electionEventId;
        public string ElectionEventId
        {
            get { return electionEventId; }
            set { this.RaiseAndSetIfChanged(ref electionEventId, value); }
        }
        
        private string emlAreaContextId;
        public string EmlAreaContextId
        {
            get
            {
                return emlAreaContextId;
            }
            set { this.RaiseAndSetIfChanged(ref emlAreaContextId, value); }
        }
        
        private string countingEmlAreaContextId;
        public string CountingEmlAreaContextId
        {
            get
            {
                return countingEmlAreaContextId;
            }
            set { this.RaiseAndSetIfChanged(ref countingEmlAreaContextId, value); }
        }
        
        private string votingCategory;
        public string VotingCategory
        {
            get { return votingCategory; }
            set { this.RaiseAndSetIfChanged(ref votingCategory, value); }
        }
        
        private string electionIdentifier;
        public string ElectionIdentifier
        {
            get { return electionIdentifier; }
            set { this.RaiseAndSetIfChanged(ref electionIdentifier, value); }
        }
        
        private string electionGroup;
        public string ElectionGroup
        {
            get { return electionGroup; }
            set { this.RaiseAndSetIfChanged(ref electionGroup, value); }
        }
        
        public bool IsFinalCounting
        {
            get { return CountingType == CountingType.Final; }
        }

        public bool IsCountingComplete
        {
            get { return CountingState == CountingState.Complete; }
        }
        private DateTime concurrencyToken;
        public DateTime ConcurrencyToken
        {
            get { return concurrencyToken; }
            set { this.RaiseAndSetIfChanged(ref concurrencyToken, value); }
        }

        public void Update(CountingModel updatedModel)
        {
            CountingState = updatedModel.CountingState;
            ConcurrencyToken = updatedModel.ConcurrencyToken;
        }
    }
}
