// RockyGuard demo: a 30-line program that loads and verifies the
// bundled sample license. Build it, run it, see "License OK" -- that
// proves the library is integrated and the API is what we say it is.
//
// What you see here is the same five-line integration shown on the
// website landing page, with a bit of error reporting wrapped around it.

#include <rockyguard/rockyguard.h>

#include <iostream>

namespace {

// The public key that matches the private key we used to sign the
// bundled sample license. In a real product, you'd replace this
// constant with YOUR public key, generated by `license_keygen`.
constexpr const char* DEMO_PUBLIC_KEY =
    "-----BEGIN PUBLIC KEY-----\n"
    "MCowBQYDK2VwAyEA8OpznE07SEteMlQoH9z6O7E+SLvdBwgPNjKsSWuPiI0=\n"
    "-----END PUBLIC KEY-----\n";

}  // namespace

int main() {
    std::cout << "RockyGuard demo - verifying sample_demo_license.json\n\n";

    rockyguard::LicenseVerifier verifier(DEMO_PUBLIC_KEY);
    auto result = verifier.load("sample_demo_license.json");
    if (!result) {
        std::cerr << "License load failed: " << result.message << "\n";
        return 1;
    }

    const auto& lic = verifier.license();
    std::cout << "License OK\n";
    std::cout << "  ID:       " << lic.license_id << "\n";
    std::cout << "  Licensee: " << lic.licensee  << "\n";
    std::cout << "  Product:  " << lic.product   << "\n";
    std::cout << "  Expires:  " << (lic.expires_at.empty() ? "permanent" : lic.expires_at) << "\n";

    // The bundled sample license uses --threshold 0 so it skips the
    // hardware-fingerprint check and runs on any machine. In your real
    // product you would call verifier.check_node_locked() here and
    // refuse to run if it returns false.
    std::cout << "\nNext step: read DEMO_README.txt and replace the embedded\n"
                 "public key + license with your own.\n";
    return 0;
}
