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

namespace CarCenterDataBaseImplement.Models
{
    public class Administrator : IAdministratorModel
    {
        public int Id { get; private set; }

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

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

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

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

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


        [ForeignKey("AdministratorId")]
        public virtual List<Equipment> Equipments { get; set; } = new();

        [ForeignKey("AdministratorId")]
        public virtual List<Car> Cars { get; set; } = new();

        [ForeignKey("AdministratorId")]
        public virtual List<Inspection> Inspections { get; set; } = new();
        public static Administrator? Create(AdministratorBindingModel model)
        {
            if (model == null)
            {
                return null;
            }
            return new Administrator()
            {
                Id = model.Id,
                AdministratorFIO = model.AdministratorFIO,
                AdministratorEmail = model.AdministratorEmail,
                AdministratorPassword = model.AdministratorPassword,
                AdministratorLogin = model.AdministratorLogin,
                AdministratorNumber = model.AdministratorNumber
            };
        }
        public static Administrator Create(AdministratorViewModel model)
        {
            return new Administrator
            {
                Id = model.Id,
                AdministratorFIO = model.AdministratorFIO,
                AdministratorEmail = model.AdministratorEmail,
                AdministratorPassword = model.AdministratorPassword,
                AdministratorLogin = model.AdministratorLogin,
                AdministratorNumber = model.AdministratorNumber
            };
        }
        public void Update(AdministratorBindingModel model)
        {
            if (model == null)
            {
                return;
            }
            AdministratorFIO = model.AdministratorFIO;
            AdministratorEmail = model.AdministratorEmail;
            AdministratorPassword = model.AdministratorPassword;
            AdministratorLogin = model.AdministratorLogin;
            AdministratorNumber = model.AdministratorNumber;
        }
        public AdministratorViewModel GetViewModel => new()
        {
            Id = Id,
            AdministratorFIO = AdministratorFIO,
            AdministratorEmail = AdministratorEmail,
            AdministratorPassword = AdministratorPassword,
            AdministratorLogin = AdministratorLogin,
            AdministratorNumber = AdministratorNumber
        };

    }
}

