//
//  HexMapDirection.hpp
//  eagle0
//
//  Created by Dan Crosby on 11/29/14.
//  Copyright (c) 2014 none. All rights reserved.
//

#ifndef eagle0_ShardokOrientation_h
#define eagle0_ShardokOrientation_h

#include "src/main/cpp/net/eagle0/common/ProtobufWarningSuppression.hpp"
#include "src/main/cpp/net/eagle0/shardok/library/ShardokException.hpp"
#pragma GCC diagnostic push
SUPPRESS_PROTOBUF_WARNINGS
#include "src/main/protobuf/net/eagle0/shardok/common/hex_map_direction.pb.h"
#pragma GCC diagnostic pop
#include <vector>

namespace shardok {

using net::eagle0::shardok::common::HexMapDirection;
using net::eagle0::shardok::common::HexMapDirection::EAST;
using net::eagle0::shardok::common::HexMapDirection::NORTHEAST;
using net::eagle0::shardok::common::HexMapDirection::NORTHWEST;
using net::eagle0::shardok::common::HexMapDirection::SOUTHEAST;
using net::eagle0::shardok::common::HexMapDirection::SOUTHWEST;
using net::eagle0::shardok::common::HexMapDirection::WEST;

inline HexMapDirection operator+(const HexMapDirection& dir, const int delta) {
    return HexMapDirection((int(dir) + delta) % 6);
}

inline HexMapDirection operator-(const HexMapDirection& dir, const int delta) {
    return HexMapDirection((int(dir) - delta) % 6);
}

inline HexMapDirection& operator++(HexMapDirection& dir) {
    dir = dir + 1;
    return dir;
}

typedef struct HexMapDirectionsTo {
    HexMapDirection main;
    HexMapDirection secondary;  // Only valid if exactly on the line
    bool usesSecondary;

    bool Matches(const HexMapDirection dir) {
        return dir == main || (usesSecondary && dir == secondary);
    }
} HexMapDirectionsTo;

inline bool operator==(const HexMapDirectionsTo& lhs, const HexMapDirectionsTo& rhs) {
    if (lhs.usesSecondary != rhs.usesSecondary) return false;
    if (!lhs.usesSecondary) return lhs.main == rhs.main;
    return (lhs.main == rhs.main && lhs.secondary == rhs.secondary) ||
           (lhs.main == rhs.secondary && lhs.secondary == rhs.main);
}
}  // namespace shardok

#endif
