#pragma once

#include <string>
#include <array>
#include <vector>
#include <map>


namespace SELCAL {

constexpr int KEYS_PER_GROUP = 2;
constexpr char GROUP_SEPARATOR = '-';

enum class Key : char {
    KEY_1 = '1',
    KEY_2 = '2',
    KEY_3 = '3',
    KEY_4 = '4',
    KEY_5 = '5',
    KEY_6 = '6',
    KEY_7 = '7',
    KEY_8 = '8',
    KEY_9 = '9',
    KEY_A = 'A',
    KEY_B = 'B',
    KEY_C = 'C',
    KEY_D = 'D',
    KEY_E = 'E',
    KEY_F = 'F',
    KEY_G = 'G',
    KEY_H = 'H',
    KEY_J = 'J',
    KEY_K = 'K',
    KEY_L = 'L',
    KEY_M = 'M',
    KEY_P = 'P',
    KEY_Q = 'Q',
    KEY_R = 'R',
    KEY_S = 'S',
    KEY_T = 'T',
    KEY_U = 'U',
    KEY_V = 'V',
    KEY_W = 'W',
    KEY_X = 'X',
    KEY_Y = 'Y',
    KEY_Z = 'Z',
};

const std::map<Key, double> KeyFrequencies = {
    {Key::KEY_1, 680.0},
    {Key::KEY_2, 754.2},
    {Key::KEY_3, 836.6},
    {Key::KEY_4, 927.9},
    {Key::KEY_5, 1029.2},
    {Key::KEY_6, 1141.6},
    {Key::KEY_7, 1266.2},
    {Key::KEY_8, 1404.4},
    {Key::KEY_9, 1557.8},
    {Key::KEY_A, 312.6},
    {Key::KEY_B, 346.7},
    {Key::KEY_C, 384.6},
    {Key::KEY_D, 426.6},
    {Key::KEY_E, 473.2},
    {Key::KEY_F, 524.8},
    {Key::KEY_G, 582.1},
    {Key::KEY_H, 645.7},
    {Key::KEY_J, 716.1},
    {Key::KEY_K, 794.3},
    {Key::KEY_L, 881.0},
    {Key::KEY_M, 977.2},
    {Key::KEY_P, 1083.9},
    {Key::KEY_Q, 1202.3},
    {Key::KEY_R, 1333.5},
    {Key::KEY_S, 1479.1},
    {Key::KEY_T, 329.2},
    {Key::KEY_U, 365.2},
    {Key::KEY_V, 405.0},
    {Key::KEY_W, 449.3},
    {Key::KEY_X, 498.3},
    {Key::KEY_Y, 552.7},
    {Key::KEY_Z, 613.1},
};

typedef std::array<Key, KEYS_PER_GROUP> Group;

class Code {
public:
    Code(std::string s);

    const std::vector<Group>& getGroups() const;

private:
    bool isValid() const;

    const std::string code;
    std::vector<Group> groups;
};

} // SELCAL
