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 CarCenterDataModels.Models;
using CarCenterContracts.BindingModels;
using CarCenterContracts.ViewModels;

namespace CarCenterDataBaseImplement.Models
{
    public class Car : ICarModel
    {
        public int Id { get; set; }
        public int AdministratorId { get; set; }

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

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

        public virtual Administrator Administrator { get; set; }

        [ForeignKey("CarId")]
        public virtual List<EquipmentCar> EquipmentCars { get; set; } = new();

        [ForeignKey("CarId")]
        public virtual List<InspectionCar> InspectionCar { get; set; } = new();
        public static Car? Create(CarBindingModel model)
        {
            if (model == null)
            {
                return null;
            }
            return new Car()
            {
                Id = model.Id,
                BrandCar = model.BrandCar,
                AdministratorId = model.AdministratorId,
                Model= model.Model
            };
        }
        public static Car Create(CarViewModel model)
        {
            return new Car
            {
                Id = model.Id,
                BrandCar = model.BrandCar,
                AdministratorId = model.AdministratorId,
                Model = model.Model
            };
        }
        public void Update(CarBindingModel model)
        {
            if (model == null)
            {
                return;
            }
            AdministratorId = model.AdministratorId;
            BrandCar = model.BrandCar;
            Model = model.Model;
        }
        public CarViewModel GetViewModel => new()
        {
            Id = Id,
            BrandCar = BrandCar,
            AdministratorId = AdministratorId,
            Model = Model
        };
    }
}
