using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using Newtonsoft.Json;
using ReallifeGamemode.Database.Models;

/**
* @overview Life of German Reallife - Entities FactionVehicles (FactionVehicle.cs)
* @author VegaZ
* @copyright (c) 2008 - 2018 Life of German
*/

namespace ReallifeGamemode.Database.Entities
{
  [Table("FactionVehicles")]
  public partial class FactionVehicle : ServerVehicle
  {
    public string Owners { get; set; }

    public List<int> GetOwners() => JsonConvert.DeserializeObject<List<int>>(Owners);

    public int BuyPrice { get; set; }

    public override string ToString()
    {
      using (var dbContext = new DatabaseContext())
        return "Fraktions Fahrzeug | Fraktion: " + string.Join(", ", dbContext.Factions.Where(f => GetOwners().Contains(f.Id)).Select(f => f.Name));
    }
  }
}
