using System.Collections.Generic;
using API.Extensions;
using API.Services.Tasks.Scanner.Parser;
namespace API.Comparators;
#nullable enable
/// 
/// Sorts chapters based on their Number. Uses natural ordering of doubles. Specials always LAST.
/// 
public class ChapterSortComparerDefaultLast : IComparer
{
    /// 
    /// Normal sort for 2 doubles. DefaultChapterNumber always comes last
    /// 
    /// 
    /// 
    /// 
    public int Compare(float x, float y)
    {
        if (x.Is(Parser.DefaultChapterNumber) && y.Is(Parser.DefaultChapterNumber)) return 0;
        // if x is 0, it comes second
        if (x.Is(Parser.DefaultChapterNumber)) return 1;
        // if y is 0, it comes second
        if (y.Is(Parser.DefaultChapterNumber)) return -1;
        return x.CompareTo(y);
    }
    public static readonly ChapterSortComparerDefaultLast Default = new ChapterSortComparerDefaultLast();
}
/// 
/// This is a special case comparer used exclusively for sorting chapters within a single Volume for reading order.
/// 
/// Volume 10 has "Series - Vol 10" and "Series - Vol 10 Chapter 81". In this case, for reading order, the order is Vol 10, Vol 10 Chapter 81.
/// This is represented by Chapter 0, Chapter 81.
/// 
/// 
public class ChapterSortComparerDefaultFirst : IComparer
{
    public int Compare(float x, float y)
    {
        if (x.Is(Parser.DefaultChapterNumber) && y.Is(Parser.DefaultChapterNumber)) return 0;
        // if x is 0, it comes first
        if (x.Is(Parser.DefaultChapterNumber)) return -1;
        // if y is 0, it comes first
        if (y.Is(Parser.DefaultChapterNumber)) return 1;
        return x.CompareTo(y);
    }
    public static readonly ChapterSortComparerDefaultFirst Default = new ChapterSortComparerDefaultFirst();
}
/// 
/// Sorts chapters based on their Number. Uses natural ordering of doubles. Specials always LAST.
/// 
public class ChapterSortComparerSpecialsLast : IComparer
{
    /// 
    /// Normal sort for 2 doubles. DefaultSpecialNumber always comes last
    /// 
    /// 
    /// 
    /// 
    public int Compare(float x, float y)
    {
        if (x.Is(Parser.SpecialVolumeNumber) && y.Is(Parser.SpecialVolumeNumber)) return 0;
        // if x is 0, it comes second
        if (x.Is(Parser.SpecialVolumeNumber)) return 1;
        // if y is 0, it comes second
        if (y.Is(Parser.SpecialVolumeNumber)) return -1;
        return x.CompareTo(y);
    }
    public static readonly ChapterSortComparerSpecialsLast Default = new ChapterSortComparerSpecialsLast();
}