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

namespace BarDatabaseImplement.Models
{
    public class Client : IClientModel
    {
        public int Id { get; private set; }
        
        [Required]
        public string ClientFIO { get; private set; } = string.Empty;
        
        [Required]
        public string Email { get; set; } = string.Empty;
        
        [Required]
        public string Password { get; set; } = string.Empty;
        
        [ForeignKey("ClientId")]
        public virtual List<Order> Orders { get; set; } = new();
        
        public static Client? Create(ClientBindingModel Model)
        {
            if (Model == null)
                return null;

            return new Client()
            {
                Id = Model.Id,
                ClientFIO = Model.ClientFIO,
                Email = Model.Email,
                Password = Model.Password
            };
        }
        
        public static Client Create(ClientViewModel Model)
        {
            return new Client()
            {
                Id = Model.Id,
                ClientFIO = Model.ClientFIO,
                Email = Model.Email,
                Password = Model.Password
            };
        }
        
        public void Update(ClientBindingModel Model)
        {
            if (Model == null)
                return;

            ClientFIO = Model.ClientFIO;
            Email = Model.Email;
            Password = Model.Password;
        }
        
        public ClientViewModel GetViewModel => new()
        {
            Id = Id,
            ClientFIO = ClientFIO,
            Email = Email,
            Password = Password,
        };
    }
}
