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

namespace GreenTree.Nachtragsmanagement.Core.Domain.Site
{
    public class Site : BaseEntity
    {
        #region Fields

        /// <summary>
        /// Userlist
        /// </summary>
        private ICollection<User.User> _users;

        /// <summary>
        /// Appendixlist
        /// </summary>
        private ICollection<Appendix.Appendix> _appendices;

        /// <summary>
        /// Deviations related to the site
        /// </summary>
        private ICollection<Deviation.Deviation> _deviations;

        #endregion

        /// <summary>
        /// CustomNumber for identification
        /// </summary>
        public string CustomNumber { get; set; }

        /// <summary>
        /// Description
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// Beginning of the site
        /// </summary>
        public DateTime? Start { get; set; }

        /// <summary>
        /// Ending of the site
        /// </summary>
        public DateTime? End { get; set; }

        /// <summary>
        /// Editable comment
        /// </summary>
        public string Comment { get; set; }

        /// <summary>
        /// Determines if the site is completely finished
        /// </summary>
        public bool Finished { get; set; }

        /// <summary>
        /// Users responsible for this site
        /// </summary>
        public virtual ICollection<User.User> Users
        {
            get { return _users ?? ( _users = new List<User.User>()); }
            protected set { _users = value; }
        }

        /// <summary>
        /// Appendices related to the site
        /// </summary>
        public virtual ICollection<Appendix.Appendix> Appendices
        {
            get { return _appendices ?? (_appendices = new List<Appendix.Appendix>()); }
            protected set { _appendices = value; }
        }

        /// <summary>
        /// Deviations related to the site
        /// </summary>
        public virtual ICollection<Deviation.Deviation> Deviations
        {
            get { return _deviations ?? (_deviations = new List<Deviation.Deviation>()); }
            protected set { _deviations = value; }
        }

        #region Helper

        /// <summary>
        /// Adds missing deviations and removes not selected deviations
        /// </summary>
        /// <param name="deviations">Site deviations.</param>
        public void SetDeviations(ICollection<Deviation.Deviation> deviations)
        {
            Deviations = deviations;
        }

        /// <summary>
        /// Adds missing appendices and removes not selected appendices
        /// </summary>
        /// <param name="deviations">Site appendices.</param>
        public void SetAppendices(ICollection<Appendix.Appendix> appendices)
        {
            Appendices = appendices;
        }

        /// <summary>
        /// Adds missing users and removes not selected users
        /// </summary>
        /// <param name="users">Site users.</param>
        public void SetUsers(ICollection<User.User> users)
        {
            Users = users;
        }

        #endregion
    }
}
