
/*
 * Copyright 2011-2022 Cuberite Contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#pragma once

#include "../CraftingRecipes.h"
#include <optional>

/**
The RecipeMapper handles the translation of crafting recipes into protocol
specific recipe Ids.
The crafting recipes are identified by the RecipeId.
The actual configuration is stored in the protocol specific configuration
directory, e.g. `Server/Protocol/1.12.2/base.recipes.txt`
*/
class cRecipeMapper
{
public:
	cRecipeMapper(void);
	~cRecipeMapper();

	/** Translates the cuberite RecipeId to the protocol specific RecipeId */
	std::optional<UInt32> GetProtocolRecipeId(UInt32 a_RecipeId, UInt32 a_ProtocolVersion);

	/** Translates the protocol specific RecipeId to the cuberite RecipeId */
	std::optional<UInt32> GetCuberiteRecipeId(UInt32 a_ProtocolRecipeId, UInt32 a_ProtocolVersion);

private:
	/** A mapping for each protocol from the protocol specific RecipeId and the cuberite RecipeId */
	std::map<AString, std::map<UInt32, UInt32>> m_ProtocolVersionMap;

	/** Load Recipes from the protocol specific mapping file */
	void loadRecipes(const AString & a_ProtocolVersion);

	/** Handles a single line of the protocol specific mapping file */
	void AddRecipeLine(const AString & a_ProtocolVersion, int a_LineNum, const AString & a_RecipeLine, const std::map<AString, UInt32> & a_RecipeNameMap);

};
