using e_suite.Database.Core.Tables.Glossaries;

namespace e_suite.Modules.GlossariesManager;

public class GlossaryCustomFieldValueKeyComparer : IComparer<GlossaryCustomFieldValue>
{
    public int Compare(GlossaryCustomFieldValue? x, GlossaryCustomFieldValue? y)
    {
        if (ReferenceEquals(x, y)) return 0;
        if (y is null) return 1;
        if (x is null) return -1;

        var glossaryIdComparison = x.GlossaryId.CompareTo(y.GlossaryId);
        if (glossaryIdComparison != 0) return glossaryIdComparison;
        var customFieldIdComparison = x.CustomFieldId.CompareTo(y.CustomFieldId);
        if (customFieldIdComparison != 0) return customFieldIdComparison;
        return x.Index.CompareTo(y.Index);
    }
}