#include "queue.hpp"
#include "workers.hpp"

#include <vector>
#include <string>
#include <fstream>
#include <ranges>
#include <format>
#include <thread>

int main() {
    std::string prefix = "./launcher/files";
    ipc::queue queue("/my_shared_queue");

    std::vector<std::string> file_list = {
        prefix + "/file1.txt",
        prefix + "/file2.txt",
        prefix + "/file3.txt"
    };

    for (auto&& name : file_list) {
        std::ofstream(name) << std::format("Hello from {}\n", name);
    }

    std::vector<std::jthread> producers;
    for (int _ : std::views::iota(0, 2)) {
        producers.emplace_back(workers::producer, std::ref(queue), std::ref(file_list));
    }

    std::vector<std::jthread> consumers;
    for (int _ : std::views::iota(0, 4)) {
        consumers.emplace_back(workers::consumer, std::ref(queue));
    }

    producers.clear();

    for (int _ : std::views::iota(0, 4)) {
        queue.push("__DONE__");
    }
}
