using CarCenterContracts.BindingModels;
using CarCenterContracts.ViewModels;
using CarCenterDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace CarCenterDataBaseImplement.Models
{
    public class Manager : IManagerModel
    {
        [Required]
        public string ManagerFIO { get; set; } = string.Empty;
        [Required]
        public string ManagerPassword { get; set; } = string.Empty;
        [Required]
        public string ManagerLogin { get; set; } = string.Empty;
        [Required]
        public string ManagerEmail { get; set; } = string.Empty;
        [Required]
        public string ManagerNumber { get; set; } = string.Empty;

        public int Id { get; private set; }

        [ForeignKey("ManagerId")]
        public virtual List<Employee> Employees { get; set; } = new();
        [ForeignKey("ManagerId")]
        public virtual List<PreSaleWork> PreSaleWorks { get; set; } = new();
        [ForeignKey("ManagerId")]
        public virtual List<Sale> Sales { get; set; } = new();

        public static Manager? Create(ManagerBindingModel model)
        {
            if (model == null)
            {
                return null;
            }
            return new Manager()
            {
                Id = model.Id,
                ManagerFIO = model.ManagerFIO,
                ManagerEmail = model.ManagerEmail,
                ManagerPassword = model.ManagerPassword,
                ManagerLogin = model.ManagerLogin,
                ManagerNumber = model.ManagerNumber
            };
        }
        public static Manager Create(ManagerViewModel model)
        {
            return new Manager
            {
                Id = model.Id,
                ManagerFIO = model.ManagerFIO,
                ManagerEmail = model.ManagerEmail,
                ManagerPassword = model.ManagerPassword,
                ManagerLogin= model.ManagerLogin,
                ManagerNumber= model.ManagerNumber
            };
        }
        public void Update(ManagerBindingModel model)
        {
            if (model == null)
            {
                return;
            }
            ManagerFIO = model.ManagerFIO;
            ManagerEmail = model.ManagerEmail;
            ManagerPassword = model.ManagerPassword;
            ManagerLogin = model.ManagerLogin;
            ManagerNumber = model.ManagerNumber;
        }
        public ManagerViewModel GetViewModel => new()
        {
            Id = Id,
            ManagerFIO = ManagerFIO,
            ManagerEmail = ManagerEmail,
            ManagerPassword = ManagerPassword,
            ManagerNumber = ManagerNumber,
            ManagerLogin = ManagerLogin
        };
    }
}
