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

namespace UniversityDataBaseImplemet.Models
{
    public class Student : IStudentModel
    {
        public int Id { get; private set; }
        [Required]
        public string Name { get; set; } = string.Empty;
        [Required]
        public string Surname { get; set; } = string.Empty;
        [Required]
        public DateTime DateOfBirth { get; set; }
        [Required]
        public int StudentCard { get; set; }
        [Required]
        public int EducationStatusId { get; set; }
        [Required]
        public int UserId { get; set; }
        [ForeignKey("StudentId")]
        public virtual List<StudentDocument> DocumentStudents { get; set; } = new();
        [ForeignKey("StudentId")]
        public virtual List<StudentStream> StudentStream { get; set; } = new();
        public virtual EducationStatus EducationStatus { get; set; }
        public virtual User User { get; set; }

        public static Student Create(StudentBindingModel model)
        {
            return new Student()
            {
                Id = model.Id,
                Name = model.Name,
                Surname = model.Surname,
                DateOfBirth = model.DateOfBirth,
                StudentCard = model.StudentCard,
                EducationStatusId = model.EducationStatusId,
                UserId = model.UserId
            };
        }
        public void Update(StudentBindingModel model)
        {
            StudentCard = model.StudentCard;
            EducationStatusId = model.EducationStatusId;
        }
        public StudentViewModel GetViewModel => new()
        {
            Id = Id,
            Name = Name,
            Surname = Surname,
            DateOfBirth = DateOfBirth,
            StudentCard = StudentCard,
            EducationStatusId = EducationStatusId,
            UserId = UserId,
            EducationStatusName = EducationStatus.Name
        };
    }
}
