/*
 * 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 "Day.h"
#include "Task.h"
#include <algorithm>
#include <stdexcept>

namespace mirai
{

int Day::id() const
{
	return dayData_.id;
}

int Day::sourceId() const
{
	return data_->id;
}

Date Day::date() const
{
	return dayData_.date;
}

std::vector<Task> Day::tasks()
{
	auto tasksData = data_->getTasksByDayId(id());
	std::vector<Task> tasks;
	std::transform(
		tasksData.begin(), tasksData.end(), std::back_inserter(tasks),
		[&](const TaskData &taskData) {
			return Task{data_, taskData};
		}
	);
	return tasks;
}

std::vector<Event> Day::events()
{
	auto eventsData = data_->getEventsByDate(dayData_.date);
	std::vector<Event> events;
	std::transform(
		eventsData.begin(), eventsData.end(), std::back_inserter(events),
		[&](const EventData &eventData) {
			return Event{data_, eventData};
		}
	);
	return events;
}

void Day::mergeDay(const Day &otherDay)
{
	throw std::runtime_error("Not implemented yet");
}
} // namespace mirai
