#ifndef _TILE_INIT_OVERRIDE_FLAG_H
#define _TILE_INIT_OVERRIDE_FLAG_H

#pragma once

#include "tile/base/internal/macro.h"
#include <string>

#define TILE_OVERRIDE_FLAG(Name, NewValue)                                                                             \
    static ::tile::detail::FlagOverriderRegistration TILE_INTERNAL_PP_CAT(                                             \
        tile_anonymous_flag_overrider_, __COUNTER__)(#Name, NewValue, false);
#define TILE_FORCE_OVERRIDE_FLAG(Name, NewValue)                                                                       \
    static ::tile::detail::FlagOverriderRegistration TILE_INTERNAL_PP_CAT(                                             \
        tile_anonymous_flag_overrider_, __COUNTER__)(#Name, NewValue, true);

namespace tile {
namespace detail {
void RegisterFlagOverrider(const std::string &name, const std::string &value, bool forcibly);
// Called by `tile::Start`
void ApplyFlagOverrider();

class FlagOverriderRegistration {
public:
    template<
        typename T,
        typename std::enable_if<std::is_trivial<T>::value && !std::is_same<T, const char *>::value>::type * = nullptr>
    FlagOverriderRegistration(const std::string &name, T value, bool forcibly)
    {
        RegisterFlagOverrider(name, std::to_string(value), forcibly);
    }

    FlagOverriderRegistration(const std::string &name, const std::string &value, bool forcibly)
    {
        RegisterFlagOverrider(name, value, forcibly);
    }
};
}// namespace detail
}// namespace tile

#endif// _TILE_INIT_OVERRIDE_FLAG_H
