using System.Collections.Generic;
public static void Main()
Console.WriteLine("Today is " + now.Date);
var offers = new List<Offer> {
new Offer(State.Available, now),
new Offer(State.Available, now.AddDays(2)),
new Offer(State.Available, now.AddDays(4)),
new Offer(State.Activated, now),
new Offer(State.Activated, now.AddDays(2)),
new Offer(State.Activated, now.AddDays(4)),
new Offer(State.Expired, now.AddDays(-1)),
new Offer(State.Expired, now.AddDays(-3)),
new Offer(State.Expired, now.AddDays(-6)),
new Offer(State.Declined, now),
new Offer(State.Declined, now.AddDays(2)),
new Offer(State.Declined, now.AddDays(4))
foreach(var offer in offers)
Console.WriteLine($"State: {offer.OfferState}, ValidTo: {offer.ValidTo}, DaysLeft: {offer.DaysLeft}");
public class Offer : IComparable<Offer>
public Offer(State state, DateTime validTo)
public State OfferState { get; }
public DateTime ValidTo { get; }
return ValidTo.Date.Subtract(DateTime.Now.Date).Days + 1;
public int CompareTo(Offer other)
if (OfferState == other.OfferState)
return DaysLeft.CompareTo(other.DaysLeft);
return other.DaysLeft.CompareTo(DaysLeft);
return DaysLeft.CompareTo(other.DaysLeft);
return CompareOfferSate(OfferState, other.OfferState);
private int CompareOfferSate(State a, State b)
var offerStateMapper = new[] { 99, 0, 1, 3, 2, 4, 99, 99, 99, 99 };
var aOrder = offerStateMapper[(int)a];
var bOrder = offerStateMapper[(int)b];
return aOrder.CompareTo(bOrder);