using System;
using System.Collections.Generic;
using System.Linq;
using QC.QTMInterface.Business_Objects.Interfaces;

namespace QC.QTMInterface.Business_Objects;

public abstract class MasterBase<T> : IFavoritesItem where T : VersionBase
{
	public long Id { get; set; }

	public string Name { get; set; }

	public long DisplayId { get; set; }

	public List<T> Versions { get; set; }

	public T LatestVersion => Versions.OrderBy((T v) => v.VersionNumber).LastOrDefault();

	public T LatestApprovedVersion => (from v in Versions
		where v.ApprovalState == ApprovalStates.Approved
		orderby v.VersionNumber
		select v).LastOrDefault();

	public bool Favorite { get; set; }

	public DateTime LastOpened { get; set; }

	public MasterBase()
	{
		Versions = new List<T>();
	}
}
