using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;

namespace DataBase;

/// <summary>
/// Таблица маршрутов
/// </summary>
public partial class Route : IRoute
{
    /// <summary>
    /// Айди маршрутта
    /// </summary>
    public int Id { get; set; }

    /// <summary>
    /// Протяженность маршрута
    /// </summary>
    public int Length { get; set; }

    /// <summary>
    /// Места прибытия
    /// </summary>
    public int? PlaceStart { get; set; }

    /// <summary>
    /// Места отправки
    /// </summary>
    public int? PlaceEnd { get; set; }

    public virtual Place? PlaceEndNavigation { get; set; }

    public virtual Place? PlaceStartNavigation { get; set; }

    public virtual ICollection<Voyage> Voyages { get; set; } = new List<Voyage>();

    [NotMapped]
    public string Title { get; set; }=string.Empty;

    public static Route Create(LogisticContext context, RouteBM model)
    {
        return new Route()
        {
            Id = model.Id,
            Title = model.Title,
            Length = model.Length,
            PlaceStart = model.PlaceStart,
            PlaceEnd = model.PlaceEnd,
            
            
        };
    }

    public void Update(RouteBM model)
    {
        Title = model.Title;
    }

    public RouteVM GetViewModel => new()
    {
        Id = Id,
        Length = Length,
        PlaceStart = PlaceStart,
        PlaceEnd = PlaceEnd,
        Title = PlaceStartNavigation?.Title + " - " + PlaceEndNavigation?.Title
    };
}