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

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

int main() {
  std::string prefix = "./task-1/files";

  th_safe::queue<std::string> 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 (std::int32_t i : std::views::iota(0, 2)) {
    producers.emplace_back(workers::producer, std::ref(queue),
                           std::ref(file_list), i);
  }

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

  producers.clear();
  queue.done();
}
