using FluentNHibernate.Conventions.Inspections;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TravelCompanyContracts.BindingModels.TouristBindingModels;
using TravelCompanyContracts.ViewModels.TouristViewModels;
using TravelCompanyDataModels.Models;

namespace TravelCompanyDatabaseImplement.Models.TouristModel
{
    public class Tourist : IUserModel
    {
        public int Id { get; set; }
        [Required]
        public string Surname { get; set; } = string.Empty;
        [Required]
        public string Name { get; set; } = string.Empty;
        public string Patronymic { get; set; } = string.Empty;
        [Required]
        public DateTime BirthDay { get; set; } = DateTime.Now;
        [Required]
        public string Login { get; set; } = string.Empty;
        [Required]
        public string Email { get; set; } = string.Empty;
        [Required]
        public string Password { get; set; } = string.Empty;
        [ForeignKey("TouristId")]
        public virtual List<Travel> Travels { get; set; } = new();
        [ForeignKey("TouristId")]
        public virtual List<Excursion> Excursions { get; set; } = new();
        [ForeignKey("TouristId")]
        public virtual List<Place> Places { get; set; } = new();

        public static Tourist? Create(TouristBindingModel model)
        {
            if (model == null)
            {
                return null;
            }
            return new Tourist()
            {
                Id = model.Id,
                Surname = model.Surname,
                Name = model.Name,
                Patronymic = model.Patronymic,
                BirthDay = model.BirthDay,
                Login = model.Login,
                Email = model.Email,
                Password = model.Password
            };
        }
        public void Update(TouristBindingModel model)
        {
            if (model == null)
            {
                return;
            }
            Id = model.Id;
            Surname = model.Surname;
            Name = model.Name;
            Patronymic = model.Patronymic;
            BirthDay = model.BirthDay;
            Login = model.Login;
            Email = model.Email;
            Password = model.Password;
        }
        public TouristViewModel GetViewModel => new()
        {
            Id = Id,
            Surname = Surname,
            Name = Name,
            Patronymic = Patronymic,
            BirthDay = BirthDay,
            Login = Login,
            Email = Email,
            Password = Password
        };
    }
}
