BareGit
#pragma once

#include <string>
#include <string_view>
#include <vector>

#include <mw/error.hpp>

#include "game.h"

/// A custom-field validation failure addressable by a form control.
struct GameFieldValidationError
{
    /// Permanent field key, or the unknown submitted key.
    std::string field_key;

    /// Safe user-facing validation message without the submitted value.
    std::string msg;
};

/// Return whether text is valid UTF-8 and contains no NUL byte.
bool validGameText(std::string_view value);

/// Decode a complete custom-field submission against one game snapshot.
mw::E<std::vector<GameFieldValue>> decodeGameFields(
    const GameDefinitionSnapshot& definition,
    const SubmittedGameFields& submitted);

/// Return the stable database spelling for a field type.
std::string_view gameFieldTypeName(GameFieldType type);

/// Parse one stable database field-type spelling.
mw::E<GameFieldType> parseGameFieldType(std::string_view value);