#>cpp
#pragma once

#include <string>

#include "utils/typeinfo.hpp"
cpp<#

(lcp:namespace query)

(lcp:define-class symbol ()
  ((name "std::string" :scope :public)
   (position :int64_t :scope :public)
   (user-declared :bool :initval "true" :scope :public)
   (type "Type" :initval "Type::ANY" :scope :public)
   (token-position :int64_t :initval "-1" :scope :public))
  (:public
    ;; This is similar to TypedValue::Type, but this has `Any` type.
    ;; TODO: Make a better Type structure which can store a generic List.
    (lcp:define-enum type (any vertex edge path number edge-list)
      (:serialize))
    #>cpp
    // TODO: Generate enum to string conversion from LCP. Note, that this is
    // displayed to the end user, so we may want to have a pretty name of each
    // value.
    static std::string TypeToString(Type type) {
      const char *enum_string[] = {"Any",  "Vertex", "Edge",
                                   "Path", "Number", "EdgeList"};
      return enum_string[static_cast<int>(type)];
    }

    Symbol() {}
    Symbol(const std::string &name, int position, bool user_declared,
           Type type = Type::ANY, int token_position = -1)
        : name_(name),
          position_(position),
          user_declared_(user_declared),
          type_(type),
          token_position_(token_position) {}

    bool operator==(const Symbol &other) const {
      return position_ == other.position_ && name_ == other.name_ &&
             type_ == other.type_;
    }
    bool operator!=(const Symbol &other) const { return !operator==(other); }

    // TODO: Remove these since members are public
    const auto &name() const { return name_; }
    int position() const { return position_; }
    Type type() const { return type_; }
    bool user_declared() const { return user_declared_; }
    int token_position() const { return token_position_; }
    cpp<#)
  (:serialize (:slk)))

(lcp:pop-namespace) ;; query

#>cpp
namespace std {

template <>
struct hash<query::Symbol> {
  size_t operator()(const query::Symbol &symbol) const {
    size_t prime = 265443599u;
    size_t hash = std::hash<int>{}(symbol.position());
    hash ^= prime * std::hash<std::string>{}(symbol.name());
    hash ^= prime * std::hash<int>{}(static_cast<int>(symbol.type()));
    return hash;
  }
};

}  // namespace std

cpp<#
