#include "fesa/core/diagnostic.hpp"

#include <algorithm>
#include <tuple>

namespace fesa {

void sortDiagnostics(std::vector<Diagnostic>& diagnostics) {
    // stable_sort makes discovery order the final tie-breaker without storing it
    // in the externally visible Diagnostic record.
    std::stable_sort(
        diagnostics.begin(),
        diagnostics.end(),
        [](const Diagnostic& left, const Diagnostic& right) {
            return std::tie(
                       left.location.file,
                       left.location.line,
                       left.keyword,
                       left.entityIdentity,
                       left.code) <
                   std::tie(
                       right.location.file,
                       right.location.line,
                       right.keyword,
                       right.entityIdentity,
                       right.code);
        });
}

} // namespace fesa
