using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;

namespace Entities.Contracts
{
	[Table("classes")]
	public class Class
	{
		[Key]
		[Column("class_id")]
		public Guid Id { get; set; }

		[Column("grade_id")]
		public Guid GradeId { get; set; }
		[ForeignKey(nameof(GradeId))]
		public virtual Grade Grade { get; set; }

		[Column("index")]
		public byte Index { get; set; }

		[Column("class_name")]
		[MaxLength(30)]
		public string ClassName { get; set; }

		[Column("head_teacher_id")]
		public Guid? HeadTeacherId { get; set; }
		[ForeignKey(nameof(HeadTeacherId))]
		public virtual User HeadTeacher { get; set; }

		[Column("created_at")]
		public DateTime CreatedAt { get; set; }

		[Column("updated_at")]
		public DateTime UpdatedAt { get; set; }

		[Column("deleted")]
		public bool IsDeleted { get; set; }

		// Navigation Properties

		[NotMapped]
		public ICollection<ClassUser> Techers => ClassUsers.Where(cu => cu.User.Role == UserRoles.Teacher).ToList();

		[NotMapped]
		public ICollection<ClassUser> Students => ClassUsers.Where(cu => cu.User.Role == UserRoles.Student).ToList();

		[InverseProperty(nameof(ClassUser.Class))]
		public virtual ICollection<ClassUser> ClassUsers { get; set; }

		public Class()
		{
			Id = Guid.NewGuid();
			ClassUsers = new HashSet<ClassUser>();
			CreatedAt = DateTime.Now;
			UpdatedAt = DateTime.Now;
		}
	}
}
