#pragma once

#include <queue>
#include <memory>
#include <mutex>
#include <condition_variable>
#include "database.h"

class ConnectionPool {
public:
    ConnectionPool(const std::string &host, const std::string &port,
                   const std::string &name, const std::string &user,
                   const std::string &password, int pool_size);

    std::shared_ptr<Database> getConnection();
    void releaseConnection(std::shared_ptr<Database> conn);

private:
    std::queue<std::shared_ptr<Database>> pool;
    std::mutex pool_mutex;
    std::condition_variable pool_cv;

    std::string host;
    std::string port;
    std::string name;
    std::string user;
    std::string password;

    void createPool(int pool_size);
    void refreshConnection(std::shared_ptr<Database> &conn);
};
