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

namespace ZooDatabaseImplements.Models
{
    public class RouteReserve : IRouteReserveModel
    {
        public int Id { get; set; }
        [Required]
        public int RouteId { get; set; }
        [Required]
        public int ReserveId { get; set; }
        [Required]
        public int Count { get; set; }
        public virtual Reserve Reserve { get; set; } = new();
        public virtual Route Route { get; set; } = new();
        [ForeignKey("RouteReserveId")]
        public virtual List<Payment> Payments { get; set; } = new();
        public static RouteReserve Create(ZooDatabase context, RouteReserveBindingModel model)
        {
            return new RouteReserve()
            {
                Id = model.Id,
                Route = context.Routes.First(x => x.Id == model.RouteId),
                Reserve = context.Reserves.First(x => x.Id == model.ReserveId)
            };
        }

        public void Update(RouteReserveBindingModel model)
        {
            Id = model.Id;
        }

        public RouteReserveViewModel GetViewModel => new()
        {
            Id = Id
        };
    }
}
