#include "fesa/core/status.hpp"

#include <utility>

namespace fesa {

Status Status::ok() {
    return Status{true, std::nullopt, {}};
}

Status Status::failure(std::vector<Diagnostic> diagnostics) {
    sortDiagnostics(diagnostics);
    return Status{false, std::nullopt, std::move(diagnostics)};
}

Status Status::failure(
    FailureCategory category, std::vector<Diagnostic> diagnostics) {
    sortDiagnostics(diagnostics);
    return Status{false, category, std::move(diagnostics)};
}

bool Status::isOk() const noexcept {
    return isOk_;
}

std::optional<FailureCategory> Status::failureCategory() const noexcept {
    return category_;
}

const std::vector<Diagnostic>& Status::diagnostics() const noexcept {
    return diagnostics_;
}

Status::Status(
    bool isOk,
    std::optional<FailureCategory> category,
    std::vector<Diagnostic> diagnostics)
    : isOk_{isOk},
      category_{category},
      diagnostics_{std::move(diagnostics)} {}

} // namespace fesa
