/*
 * Copyright 2016 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
 */

#pragma once

#include <ox/std/string.hpp>
#include <ox/std/vector.hpp>

#include <ox/model/def.hpp>

namespace studio {

struct StudioConfigV1 {
	static constexpr auto TypeName = "net.drinkingtea.studio.StudioConfig";
	static constexpr auto TypeVersion = 1;
	ox::String projectPath;
	ox::String activeTabItemName;
	ox::Vector<ox::String> openFiles;
	bool showProjectExplorer = true;
};

OX_MODEL_BEGIN(StudioConfigV1)
	OX_MODEL_FIELD_RENAME(activeTabItemName, active_tab_item_name)
	OX_MODEL_FIELD_RENAME(projectPath, project_path)
	OX_MODEL_FIELD_RENAME(openFiles, open_files)
	OX_MODEL_FIELD_RENAME(showProjectExplorer, show_project_explorer)
OX_MODEL_END()


struct StudioConfigV2 {
	static constexpr auto TypeName = "net.drinkingtea.studio.StudioConfig";
	static constexpr auto TypeVersion = 2;
	struct ProjectConfig {
		static constexpr auto TypeName = "net.drinkingtea.studio.ProjectConfig";
		static constexpr auto TypeVersion = 2;
		ox::String projectPath;
		ox::String activeTabItemName;
		ox::Vector<ox::String> openFiles;
	};
	ox::Vector<ProjectConfig> projects;
	bool showProjectExplorer = true;

	[[nodiscard]]
	constexpr ProjectConfig const *project() const {
		return projects.empty() ? nullptr : &projects[0];
	}

	[[nodiscard]]
	constexpr ProjectConfig *project() {
		return projects.empty() ? nullptr : &projects[0];
	}
};

OX_MODEL_BEGIN(StudioConfigV2::ProjectConfig)
	OX_MODEL_FIELD_RENAME(activeTabItemName, active_tab_item_name)
	OX_MODEL_FIELD_RENAME(projectPath, project_path)
	OX_MODEL_FIELD_RENAME(openFiles, open_files)
OX_MODEL_END()

OX_MODEL_BEGIN(StudioConfigV2)
	OX_MODEL_FIELD(projects)
	OX_MODEL_FIELD_RENAME(showProjectExplorer, show_project_explorer)
OX_MODEL_END()

using StudioConfig = StudioConfigV2;

}
