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

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

        /// <summary>
        /// Users related to the role
        /// </summary>
        private ICollection<User> _users;

        /// <summary>
        /// Functionlist
        /// </summary>
        private ICollection<Function> _functions;

        #endregion

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

        /// <summary>
        /// Level of right (higher value means higher right)
        /// </summary>
        public int Level { get; set; }

        /// <summary>
        /// Determines if the role can only see sites which it is assigned to
        /// </summary>
        public bool SeeOnlyAssigned { get; set; }

        /// <summary>
        /// Users assigned to the role
        /// </summary>
        public virtual ICollection<User> Users
        {
            get { return _users ?? (_users = new List<User>()); }
            protected set { _users = value; }
        }

        /// <summary>
        /// Functions the role have
        /// </summary>
        public virtual ICollection<Function> Functions
        {
            get { return _functions ?? (_functions = new List<Function>()); }
            protected set { _functions = value; }
        }

        #region Helper

        /// <summary>
        /// Adds missing functions and removes not selected functions
        /// </summary>
        /// <param name="functions">Functions.</param>
        public void SetFunctions(ICollection<Function> functions)
        {
            Functions = functions;
        }

        #endregion
    }
}
