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.OperatorBindingModels;
using TravelCompanyContracts.ViewModels.OperatorViewModels;
using TravelCompanyDataModels.Models;

namespace TravelCompanyDatabaseImplement.Models.OperatorModels
{
    public class Operator : 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("OperatorId")]
        public virtual List<Tour> Tours { get; set; } = new();
        [ForeignKey("OperatorId")]
        public virtual List<Guide> Guides { get; set; } = new();
        public static Operator? Create(OperatorBindingModel model)
        {
            if (model == null)
            {
                return null;
            }
            return new Operator()
            {
                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(OperatorBindingModel 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 OperatorViewModel GetViewModel => new()
        {
            Id = Id,
            Surname = Surname,
            Name = Name,
            Patronymic = Patronymic,
            BirthDay = BirthDay,
            Login = Login,
            Email = Email,
            Password = Password
        };

    }
}
