/*
 * 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
 */

#pragma once

#include "DataProvider.h"
#include "DateTime.h"
#include "Day.h"
#include "Event.h"
#include "Task.h"
#include <string>
#include <vector>

namespace mirai
{

struct createTaskParams {
	std::string title;
	std::optional<Event> event;
	std::optional<Date> date;
};

struct createEventParams {
	std::string title;
	Date date;
	Time startsAt;
	Time endsAt;
};

struct SourceConstructor {
	DataProvider *sourceDataProvider;
};

class Source
{
  public:
	Source(SourceConstructor params) : data(params.sourceDataProvider)
	{
	}

	Source(Source &) = delete;
	Source(Source &&) = delete;
	Source operator=(Source &) = delete;
	Source operator=(Source &&) = delete;

	~Source() = default;

	void init();
	void save();
	void load();

	std::string name() const;

	void createTask(const createTaskParams &task);
	void removeTask(const Task &task);
	std::optional<Task> getTaskById(int taskId);
	std::vector<Task> getTasksByDate(Date date);
	std::vector<Task> getUnscheduledTasks();
	std::vector<Task> getTasks();

	void createEvent(const createEventParams &eventToCreate);
	void removeEvent(const Event &event);
	std::vector<Event> getEvents();
	std::optional<Event> getEventById(int eventId);
	std::vector<Event> getEventsByDate(Date date);

	std::vector<Day> getDays();
	std::optional<Day> getDayByDate(Date date);

	const int id = Source::generateNextId();

	bool isDirty() const
	{
		return data->isDirty();
	};

  private:
	static int generateNextId()
	{
		static int nextId = 0;
		return nextId++;
	}

	DataProvider *data;
};
} // namespace mirai
