using e_suite.Database.Core.Tables.Forms;

namespace e_suite.Modules.FormsManager;

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

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