using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZooDataModels.Models;
using ZooContracts.BindingModels;
using ZooContracts.ViewModels;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;

namespace ZooDatabaseImplements.Models
{
    public class Reserve : IReserveModel
    {
        public int Id { get; private set; }
        [Required]
        public string ReserveName { get; private set; } = string.Empty;
        [Required]
        public double ReservePrice { get; private set; }
        [Required]
        public int EmployeeId { get; private set; }
        public virtual Employee Employee { get; private set; } = new();
        [ForeignKey("ReserveId")]
        public virtual List<RouteReserve> RouteReserves { get; set; } = new();
        [ForeignKey("ReserveId")]
        public virtual List<Payment> Payments { get; set; } = new();
        public static Reserve? Create(ZooDatabase context, ReserveBindingModel model)
        {
            if (model == null)
            {
                return null;
            }
            return new Reserve()
            {
                Id = model.Id,
                ReserveName = model.ReserveName,
                ReservePrice = model.ReservePrice,
                Employee = context.Employees.First(x => x.Id == model.EmployeeId)
            };
        }
        public static Reserve Create(ReserveViewModel model)
        {
            return new Reserve
            {
                Id = model.Id,
                ReserveName = model.ReserveName,
                ReservePrice = model.ReservePrice,
                EmployeeId = model.EmployeeId
            };
        }
        public void Update(ReserveBindingModel model)
        {
            if (model == null)
            {
                return;
            }
            ReserveName = model.ReserveName;
            ReservePrice = model.ReservePrice;
            EmployeeId = model.EmployeeId;
        }
        public ReserveViewModel GetViewModel => new()
        {
            Id = Id,
            ReserveName = ReserveName,
            ReservePrice = ReservePrice,
            EmployeeId = EmployeeId
        };
    }
}
