#pragma once
#ifndef __GAMEDATAMANAGER_H__
#define __GAMEDATAMANAGER_H__

struct CeraShopBonusCodeType
{
	int code_min;
	int code_max;
	int code_count;
};

struct CeraShopBonusItemType
{

	int item_id;
	int item_num;
	bool is_random;
};


class CGameDataManager
{
public:
	RINDRO_SINGLETON_DEFINE_S(CGameDataManager);

	CGameDataManager()
	{
		cera_shop_bonus_code_array.clear();
		cera_shop_bonus_item_map.Clear();
	}
	~CGameDataManager() {};
public:

	bool is_cera_shop_bonus_code(int code_id, CeraShopBonusCodeType* res = NULL)
	{
		for (size_t i = 0; i < cera_shop_bonus_code_array.size(); i++)
		{
			CeraShopBonusCodeType cera_shop_bonus_code_ = cera_shop_bonus_code_array.at(i);
			if (code_id >= cera_shop_bonus_code_.code_min && code_id <= cera_shop_bonus_code_.code_max)
			{
				if (res != NULL) *res = cera_shop_bonus_code_;
				return true;
			}
		}
		return false;
	}

	bool get_rand_cera_shop_bonus_item(CeraShopBonusItemType* res = NULL)
	{
		int rand_ = Utils::Rand(0, get_random_item_num() - 1);
		int i = 0;
		for (auto it = cera_shop_bonus_item_map_rand.Begin(); it != cera_shop_bonus_item_map_rand.End(); it++, i++)
		{
			if (rand_ == i)
			{
				if (res) *res = it->second;
				return true;
			}
		}
		return false;
	}

	int get_random_item_num()
	{
		return cera_shop_bonus_item_map_rand.Size();
	}

	bool add_cera_shop_bonus_item(int count_, int item_id, int item_num, bool is_random)
	{
		cera_shop_bonus_item_map.Push(count_, { item_id ,item_num ,is_random });
	}

	Utils::TMap<int, CeraShopBonusItemType>* get_cera_shop_bonus_item_map()
	{
		return &cera_shop_bonus_item_map;
	}

	std::vector<CeraShopBonusCodeType>* get_cera_shop_bonus_code_array()
	{
		return &cera_shop_bonus_code_array;
	}

	Utils::TMap<int, CeraShopBonusItemType>* get_cera_shop_bonus_item_map_rand()
	{
		return &cera_shop_bonus_item_map_rand;
	}


protected:


private:

	std::vector<CeraShopBonusCodeType> cera_shop_bonus_code_array;

	Utils::TMap<int, CeraShopBonusItemType>  cera_shop_bonus_item_map;	// 次数 + 数据
	Utils::TMap<int, CeraShopBonusItemType>  cera_shop_bonus_item_map_rand;	// 次数 + 数据
};


#endif // __GAMEDATAMANAGER_H__

