#include "pairing.hpp"
#include <chrono>

static uint64_t now_ms() {
    return std::chrono::duration_cast<std::chrono::milliseconds>(
        std::chrono::system_clock::now().time_since_epoch()).count();
}

void PairingStore::set_pairing_code(const std::string& code, const std::string& name) {
    auth_codes_[code] = {code, name, now_ms()};
}

void PairingStore::revoke_pairing_code(const std::string& code) {
    auth_codes_.erase(code);
}

bool PairingStore::has_pairing_code(const std::string& code) const {
    return auth_codes_.count(code) > 0;
}

void PairingStore::register_device(const std::string& token, const std::string& name) {
    paired_devices_[token] = {name, token, now_ms()};
}

const std::unordered_map<std::string, DeviceEntry>& PairingStore::get_paired_devices() const {
    return paired_devices_;
}
