// Copyright (c) 2025-2026 Rocky Software Inc.
// All rights reserved.
//
// This file is part of the RockyGuard library and is distributed under
// the terms of the RockyGuard Library Software License Agreement. See
// docs/RockyGuard_License_Agreement.pdf in the distribution.
//
// No part of this file may be copied, modified, or distributed except
// as expressly permitted by the license agreement.

#pragma once

#include "types.h"
#include <atomic>
#include <memory>
#include <string>
#include <thread>

namespace rockyguard {

struct FloatingClientConfig {
    std::string server_host = "127.0.0.1";
    uint16_t server_port = 8080;
    int heartbeat_interval_sec = 60;

    // Response verification: public key to verify server signatures
    std::string server_public_key_pem;  // PEM string; empty = skip verification

    // TLS: set to true if server uses TLS
    bool use_tls = false;
    std::string tls_ca_cert_path;  // Path to server cert for verification (recommended)
                                   // Empty = accept any cert (warns, vulnerable to MITM)
};

class ROCKYGUARD_API FloatingLicenseClient {
public:
    explicit FloatingLicenseClient(const FloatingClientConfig& config);
    ~FloatingLicenseClient();

    FloatingLicenseClient(const FloatingLicenseClient&) = delete;
    FloatingLicenseClient& operator=(const FloatingLicenseClient&) = delete;

    // Acquire a license from the pool
    LicenseResult checkout();

    // Release the license back to the pool
    LicenseResult checkin();

    // Query server status
    bool is_checked_out() const;

private:
    struct Impl;
    std::unique_ptr<Impl> impl_;
};

} // namespace rockyguard
