using DressAtelierDataModels.Models;
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;
using DressAtelierDatabaseImplementation.Models;
using DressAtelierContracts.ViewModels;
using DressAtelierContracts.BindingModels;

namespace DressAtelierDatabaseImplement.Models
{
    public class Employee : IEmployeeModel
    {
        public int ID { get; private set; }
        [Required]
        public string FullName { get; private set; } = string.Empty;
        [Required]
        public int WorkExperience { get; private set; } 
        [Required]
        public string Password { get; private set; } = string.Empty;
        [Required]
        public int Qualification { get; private set; }

        [ForeignKey("EmployeeID")]
        public virtual List<Order>? Orders { get; set; } = new();

        public static Employee? Create(EmployeeBindingModel model)
        {
            if(model == null)
            {
                return null;
            }
            return new Employee
            {
                ID = model.ID,
                FullName = model.FullName,
                WorkExperience = model.WorkExperience,
                Password = model.Password,
                Qualification = model.Qualification
            };
        }

        public void Update(EmployeeBindingModel model) 
        {
            if(model == null) 
            { 
                return;
            } 
            FullName = model.FullName;
            WorkExperience = model.WorkExperience;
            Password = model.Password;
            Qualification = model.Qualification;
        }

        public EmployeeViewModel GetViewModel => new()
        {
            ID = ID,
            FullName = FullName,
            WorkExperience = WorkExperience,
            Password = Password,
            Qualification = Qualification
        };
    }
}
