using BarContracts.BindingModels;
using BarContracts.ViewModels;
using BarDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace BarDatabaseImplement.Models
{
    public class Implementer : IImplementerModel
    {
        public int Id { get; set; }

        [Required]
        public string ImplementerFIO { get; set; } = string.Empty;

        [Required]
        public string Password { get; set; } = string.Empty;

        [Required]
        public int WorkExperience { get; set; }

        [Required]
        public int Qualification { get; set; }

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

        public static Implementer? Create(ImplementerBindingModel? Model)
        {
            if (Model == null)
                return null;
            
            return new Implementer()
            {
                Id = Model.Id,
                ImplementerFIO = Model.ImplementerFIO,
                Password = Model.Password,
                WorkExperience = Model.WorkExperience,
                Qualification = Model.Qualification
            };
        }

        public void Update(ImplementerBindingModel Model)
        {
            if (Model == null)
            {
                return;
            }
            ImplementerFIO = Model.ImplementerFIO;
            Password = Model.Password;
            WorkExperience = Model.WorkExperience;
            Qualification = Model.Qualification;
        }

        public ImplementerViewModel GetViewModel => new()
        {
            Id = Id,
            ImplementerFIO = ImplementerFIO,
            Password = Password,
            WorkExperience = WorkExperience,
            Qualification = Qualification
        };
    }
}
