using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Entities.Contracts
{
	public enum Layout : byte
	{
		horizontal = 0,
		vertical = 1,

		Auto = 2
	}

	public enum Publisher : byte
	{
		Unknown = 0,
		统编版,
		部编版,
	}

	public enum GradeEnum : byte
	{
		Unknown = 0,
		一年级 = 1,
		二年级 = 2,
		三年级 = 3,
		四年级 = 4,
		五年级 = 5,
		六年级 = 6
	}

	public enum DifficultyLevel : byte
	{
		simple,
		easy,
		medium,
		hard,
		veryHard
	}

	public enum TypeNameType : byte
	{
		Subject = 0,
		QuestionType = 1,
		ExamType = 2,
	}

	public enum SubjectAreaEnum : byte
	{
		[Display(Name = "未知", Description = "未知")]
		Unknown = 0,

		[Display(Name = "数学", Description = "数")]
		Mathematics,      // 数学

		[Display(Name = "物理", Description = "物")]
		Physics,          // 物理

		[Display(Name = "化学", Description = "化")]
		Chemistry,        // 化学

		[Display(Name = "生物", Description = "生")]
		Biology,          // 生物

		[Display(Name = "历史", Description = "史")]
		History,          // 历史

		[Display(Name = "地理", Description = "地")]
		Geography,        // 地理

		[Display(Name = "语文", Description = "语")]
		Literature,      // 语文/文学

		[Display(Name = "英语", Description = "英")]
		English,          // 英语

		[Display(Name = "计算机科学", Description = "计")]
		ComputerScience // 计算机科学
	}

	public enum ExamStructType : byte
	{
		[Display(Name = "根节点", Description = "根")]
		Root,
		[Display(Name = "单个问题", Description = "问")]
		Question,
		[Display(Name = "问题组", Description = "组")]
		Group,
		[Display(Name = "结构", Description = "结")]
		Struct,
		[Display(Name = "子问题", Description = "子")]
		SubQuestion,
		[Display(Name = "选项", Description = "选")]
		Option
	}
	
	public enum UserRoles
	{
		Student,
		Teacher,
		Admin
	}

	public enum SubmissionStatus
	{
		[Display(Name = "待提交/未开始", Description = "待")]
		Pending,

		[Display(Name = "已提交", Description = "提")]
		Submitted,

		[Display(Name = "已批改", Description = "批")]
		Graded,

		[Display(Name = "待重新提交", Description = "重")]
		Resubmission,

		[Display(Name = "迟交", Description = "迟")]
		Late,

		[Display(Name = "草稿", Description = "草")]
		Draft,
	}

	public static class EnumExtensions
	{
		public static string GetDisplayName(this Enum enumValue)
		{
			var fieldInfo = enumValue.GetType().GetField(enumValue.ToString());

			if (fieldInfo == null)
			{
				return enumValue.ToString(); 
			}

			var displayAttribute = fieldInfo.GetCustomAttribute<DisplayAttribute>();

			if (displayAttribute != null)
			{
				return displayAttribute.Name;
			}

			return enumValue.ToString();
		}

		public static string GetShortName(this Enum enumValue)
		{
			var memberInfo = enumValue.GetType().GetMember(enumValue.ToString()).FirstOrDefault();

			if (memberInfo != null)
			{
				var displayAttribute = memberInfo.GetCustomAttribute<DisplayAttribute>();

				if (displayAttribute != null && !string.IsNullOrEmpty(displayAttribute.Description))
				{
					return displayAttribute.Description;
				}
			}

			return enumValue.ToString();
		}
	}
}
