﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using SocketDog.Common;
using SocketDog.Core.ContractsRepo;

namespace SocketDog.Core.Entities
{
    public class ConnectionEntity : IEntity, 
        IEquatable<ConnectionEntity>, IEquatable<Guid>
    {
        private int _qnt;
        private int _limit;
        private int _updateSec;

        public Guid Id { get; set; }
        public int Index { get; set; }
        public string Address { get; set; }
        public ConnectionProtocol.Type ProtocolType { get; set; }

        public int UpdateSec
        {
            get { return _updateSec; }
            set
            {
                _updateSec = value;
                UpdateSecChanged(this, value);
            }
        }

        public int Qnt
        {
            get { return _qnt; }
            set
            {
                _qnt = value;
                QuantityChanged(this, value);
            }
        }

        public int Limit
        {
            get { return _limit; }
            set
            {
                _limit = value;
                LimitChanged(this, value);
            }
        }

        public event EventHandler<int> UpdateSecChanged = delegate { };
        public event EventHandler<int> QuantityChanged = delegate { };
        public event EventHandler<int> LimitChanged = delegate { };

        public bool Equals(ConnectionEntity other)
        {
            return other != null && Equals(other.Id);
        }

        public bool Equals(Guid other)
        {
            return Id.Equals(other);
        }
    }
}
