/* * Mirai. Copyright (C) 2024 Vyn * This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only) * The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt */ #include "Task.h" #include "DataProvider.h" #include "utils.h" #include #include namespace mirai { int Task::id() const { return task_.id; } int Task::source_id() const { return data_->id; } std::string Task::title() const { return task_.title; } mirai::task_state Task::state() const { return task_.state; } bool Task::checked() const { return task_.state == mirai::DONE; } bool Task::has_due_date() const { return task_.due_date.has_value(); } std::optional Task::due_date() const { if (!task_.due_date.has_value()) { return std::nullopt; } return task_.due_date.value(); } void Task::set_title(const std::string &newTitle) { data_->update_task(id(), {.title = newTitle}); } void Task::set_date(const Date &date) { auto emptyEventId = std::optional>(std::optional(std::nullopt)); data_->update_task(id(), {.due_date = date}); } void Task::unschedule() { auto emptyId = std::optional>(std::optional(std::nullopt)); data_->update_task(id(), {.due_date = std::nullopt}); } void Task::set_checked(bool checked) { data_->update_task(id(), {.state = checked ? DONE : TODO}); } } // namespace mirai