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

namespace SchoolDatabase.Models
{
	public class CoursesForStudy: ICoursesForStudy
	{
		public int Id { get; private set; }
		[Required, Column(TypeName = "decimal (10,2)")]
		public decimal TotalTime { get; private set; }
		[Required]
		public int StudyId { get; private set; }
		[Required]
		public int CoursesId { get; private set; }
		
		// Оплаты за обучение
		[ForeignKey("CoursesForStudyId")]
		public virtual List<Payment> Payments { get; set; } = new();
		public static CoursesForStudy? Create(CoursesForStudyBindingModel? model)
		{
			if (model == null)
			{
				return null;
			}
			return new()
			{
				Id = model.Id,
				TotalTime = model.TotalTime,
				StudyId = model.StudyId,
				CoursesId = model.CoursesId
			};
		}
		public static CoursesForStudy Create(CoursesForStudyViewModel model)
		{
			return new()
			{
				Id = model.Id,
				TotalTime = model.TotalTime,
				StudyId = model.StudyId,
				CoursesId = model.CoursesId
			};
		}
		public void Update(CoursesForStudyBindingModel? model)
		{
			if (model == null)
			{
				return;
			}
			Id = model.Id;
			TotalTime = model.TotalTime;
			StudyId = model.StudyId;
			CoursesId = model.CoursesId;
		}
		public CoursesForStudyViewModel GetViewModel => new()
		{
			Id = Id,
			TotalTime = TotalTime,
			StudyId = StudyId,
			CoursesId = CoursesId
		};
	}
}
