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 TravelCompanyDataModels.Models.TouristModels;
using TravelCompanyContracts.BindingModels.TouristBindingModels;
using TravelCompanyContracts.ViewModels.TouristViewModels;

namespace TravelCompanyDatabaseImplement.Models.TouristModel
{
    public class Place : IPlaceModel
    {
        public int Id { get; set; }
        [Required]
        public string PlaceName { get; set; } = string.Empty;
        [Required]
        public string PlaceAddress { get; set; } = string.Empty;

        [Required]
        public int ExcursionId { get; set; }
        public virtual Excursion Excursion { get; set; }
        [Required]
        public int TouristId { get; set; }
        public virtual Tourist Tourist { get; set; }
 

        public static Place? Create(PlaceBindingModel model)
        {
            if (model == null)
            {
                return null;
            }
            return new Place()
            {
                Id = model.Id,
                PlaceName = model.PlaceName,
                PlaceAddress = model.PlaceAddress,
                ExcursionId = model.ExcursionId,
                TouristId = model.TouristId
            };
        }
        public void Update(PlaceBindingModel model)
        {
            if (model == null)
            {
                return;
            }
            PlaceName = model.PlaceName;
            PlaceAddress = model.PlaceAddress;
            ExcursionId = model.ExcursionId;
        }
        public PlaceViewModel GetViewModel => new PlaceViewModel
        {
            Id = Id,
            PlaceName = PlaceName,
            PlaceAddress = PlaceAddress,
            ExcursionId = ExcursionId,
            ExcursionName = Excursion?.ExcursionName,
            TouristId = TouristId,
        };
    }
}
