using SchoolContracts.BindingModels;
using SchoolContracts.Models;
using SchoolContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SchoolDatabase.Models
{
	public class Worker : IWorkerModel
	{
		public int Id { get; private set; }
		[Required]
		public string Login { get; private set; } = string.Empty;
		[Required]
		public string Email { get; private set; } = string.Empty;
		[Required]
		public string FIO { get; private set; } = string.Empty;
		[Required]
		public string Post { get; private set; } = string.Empty;
		[Required]
		public string Password { get; private set; } = string.Empty;

		// Работы
		[ForeignKey("WorkerId")]
		public virtual List<Courses> Courses { get; set; } = new();

		// Статьи затрат
		[ForeignKey("WorkerId")]
		public virtual List<Item> Items { get; set; } = new();
		public static Worker? Create(WorkerBindingModel? model)
		{
			if (model == null)
			{
				return null;
			}
			return new()
			{
				Login = model.Login,
				Email = model.Email,
				FIO = model.FIO,
				Post = model.Post,
				Password = model.Password
			};
		}
		public void Update(WorkerBindingModel? model)
		{
			if (model == null)
			{
				return;
			}
			Login = model.Login;
			Email = model.Email;
			FIO = model.FIO;
			Post = model.Post;
			Password = model.Password;
		}
		public WorkerViewModel GetViewModel => new()
		{
			Id = Id,
			Login = Login,
			Email = Email,
			FIO = FIO,
			Post = Post,
			Password = Password
		};
	}
}
