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

namespace Valg.EVA.Skanning.JobManagement.Startup.Data
{
    public class BoxCountingDetailsModel : ReactiveObject, IUpdatable<BoxCountingDetailsModel, int>
    {
        private int id;
        private int countingId;
        private BoxCountingState boxCountingState;
        private string barcodeLong;
        private string barcodeShort;
        private DateTime concurrencyToken;
        private int ballotsToVerify;
        private int scannedBallots;
        private CountingType countingType;

        public BoxCountingDetailsModel()
        {
            this.Bubble(
                m => m.BallotsToVerify,
                m => m.HasBallotsToVerify);
            this.Bubble(
                m => m.ScannedBallots,
                m => m.HasScannedBallots);
        }

        public int Id
        {
            get { return id; }
            set { this.RaiseAndSetIfChanged(ref id, value); }
        }
        public int CountingId
        {
            get { return countingId; }
            set { this.RaiseAndSetIfChanged(ref countingId, value); }
        }
        public BoxCountingState BoxCountingState
        {
            get { return boxCountingState; }
            set { this.RaiseAndSetIfChanged(ref boxCountingState, value); }
        }
        public string BarcodeLong
        {
            get { return barcodeLong; }
            set { this.RaiseAndSetIfChanged(ref barcodeLong, value); }
        }
        public string BarcodeShort
        {
            get { return barcodeShort; }
            set { this.RaiseAndSetIfChanged(ref barcodeShort, value); }
        }
        public DateTime ConcurrencyToken
        {
            get { return concurrencyToken; }
            set { this.RaiseAndSetIfChanged(ref concurrencyToken, value); }
        }

        public int BallotsToVerify
        {
            get { return ballotsToVerify; }
            set { this.RaiseAndSetIfChanged(ref ballotsToVerify, value); }
        }

        public int ScannedBallots
        {
            get { return scannedBallots; }
            set { this.RaiseAndSetIfChanged(ref scannedBallots, value); }
        }

        public CountingType CountingType
        {
            get { return countingType; }
            set { this.RaiseAndSetIfChanged(ref countingType, value); }
        }


        public bool HasScannedBallots { get { return ScannedBallots > 0;  } }
        public bool HasBallotsToVerify { get { return BallotsToVerify > 0; } }

        public void Update(BoxCountingDetailsModel updatedModel)
        {
            BoxCountingState = updatedModel.BoxCountingState;
            ConcurrencyToken = updatedModel.ConcurrencyToken;
            BallotsToVerify = updatedModel.BallotsToVerify;
            ScannedBallots = updatedModel.ScannedBallots;
        }
    }
}

