Files
2026-10-29 01:02:06 -03:00

59 lines
2.3 KiB
C++

#pragma once
#include <cstddef>
#include <ctime>
#include <optional>
#include <string>
#include <vector>
#include "Database.h"
#include "Status.h"
// How taken an account is, judged by its tasks:
// Free - only Done, Frozen or Uploading tasks, or no tasks
// Taken - has a Prompt task (and nothing Busy)
// Busy - has a Testing, Limit reset or Wait task, or is waiting itself
enum class AccountLevel { Busy, Taken, Free };
std::string accountLevelName(AccountLevel level); // "busy", "taken", "free"
// An account waits from the moment it hits its limit until the wait time; after
// that it is not waiting any more (its Wait tasks are then Limit reset).
enum class WaitState { None, Waiting };
// A task as the user sees it: the status is computed from the stored status,
// the account's wait and the current time.
struct TaskInfo {
std::string name;
std::optional<std::string> account;
Status status; // as shown (a Wait task becomes Limit reset when its account's wait ends)
Status storedStatus; // what is saved underneath
// What the panel shows: "Wait 16:30", "Limit reset", "Testing (account-waiting)"...
std::string statusLabel;
// Prompt / Testing while its account waits: shown as they are, with
// "(account-waiting)" appended.
bool accountWaiting = false;
std::string notes;
std::size_t noteLines = 0;
};
struct AccountInfo {
std::string name;
AccountLevel level = AccountLevel::Free;
WaitState waitState = WaitState::None;
std::time_t waitUntil = 0; // when the wait ends; 0 if it is not waiting
// True when the account is waiting but none of its tasks is set to Wait
// (e.g. it has no tasks). It still makes the account Busy.
bool waitListed = false;
std::vector<std::string> tasks; // tasks at the account's level (Free: its Uploading/Frozen/Done ones)
};
// Tasks in display order: status priority (Limit reset, Testing, Prompt, Wait,
// Uploading, Frozen, Done); for Wait and Limit reset then time, earliest first;
// then account A-Z (none last); then task name.
std::vector<TaskInfo> buildTasks(const Database& db, std::time_t now);
// Accounts in display order, most free first: Free, Taken, Busy; within Taken
// and Busy fewer entries first; ties by name.
std::vector<AccountInfo> buildAccounts(const Database& db, std::time_t now);