/* Copyright 2020, Michele Santullo
 * This file is part of orotool.
 *
 * Orotool is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Orotool is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Orotool.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "items.hpp"
#include <stdexcept>

namespace oro {
ItemTypeWrapper::ItemTypeWrapper (const std::string& str) {
	*this = str;
}

ItemTypeWrapper::ItemTypeWrapper (std::string_view str) {
	*this = str;
}

ItemTypeWrapper& ItemTypeWrapper::operator= (const std::string& str) {
	return this->operator=(std::string_view(str));
}

ItemTypeWrapper& ItemTypeWrapper::operator= (std::string_view str) {
	if ("IT_HEALING" == str)
		value = ItemType::Healing;
	else if ("IT_UNKNOWN" == str)
		value = ItemType::Unknown;
	else if ("IT_USABLE" == str)
		value = ItemType::Usable;
	else if ("IT_ETC" == str)
		value = ItemType::Etc;
	else if ("IT_WEAPON" == str)
		value = ItemType::Weapon;
	else if ("IT_ARMOR" == str)
		value = ItemType::Armor;
	else if ("IT_CARD" == str)
		value = ItemType::Card;
	else if ("IT_PETEGG" == str)
		value = ItemType::PetEgg;
	else if ("IT_PETARMOR" == str)
		value = ItemType::PetArmor;
	else if ("IT_UNKNOWN2" == str)
		value = ItemType::Unknown2;
	else if ("IT_AMMO" == str)
		value = ItemType::Ammo;
	else if ("IT_DELAYCONSUME" == str)
		value = ItemType::DelayConsume;
	else if ("IT_CASH" == str)
		value = ItemType::Cash;
	else
		throw std::runtime_error("Unknown item type \"" + std::string(str) + "\"");
	return *this;
}

ItemSubtypeWrapper::ItemSubtypeWrapper (const std::string& str) {
	*this = str;
}

ItemSubtypeWrapper::ItemSubtypeWrapper (std::string_view str) {
	*this = str;
}

ItemSubtypeWrapper& ItemSubtypeWrapper::operator= (const std::string& str) {
	return this->operator=(std::string_view(str));
}

ItemSubtypeWrapper& ItemSubtypeWrapper::operator= (std::string_view str) {
	//For IT_WEAPON:
	if ("W_FIST" == str)
		value = ItemSubtype::Fist;
	else if ("W_DAGGER" == str)
		value = ItemSubtype::Dagger;
	else if ("W_1HSWORD" == str)
		value = ItemSubtype::OneHSword;
	else if ("W_2HSWORD" == str)
		value = ItemSubtype::TwoHSword;
	else if ("W_1HSPEAR" == str)
		value = ItemSubtype::OneHSpear;
	else if ("W_2HSPEAR" == str)
		value = ItemSubtype::TwoHSpear;
	else if ("W_1HAXE" == str)
		value = ItemSubtype::OneHAxe;
	else if ("W_2HAXE" == str)
		value = ItemSubtype::TwoHAxe;
	else if ("W_MACE" == str)
		value = ItemSubtype::Mace;
	else if ("W_2HMACE" == str)
		value = ItemSubtype::TwoHMace;
	else if ("W_STAFF" == str)
		value = ItemSubtype::Staff;
	else if ("W_2HSTAFF" == str)
		value = ItemSubtype::TwoHStaff;
	else if ("W_BOW" == str)
		value = ItemSubtype::Bow;
	else if ("W_KNUCKLE" == str)
		value = ItemSubtype::Knuckle;
	else if ("W_MUSICAL" == str)
		value = ItemSubtype::Musical;
	else if ("W_WHIP" == str)
		value = ItemSubtype::Whip;
	else if ("W_BOOK" == str)
		value = ItemSubtype::Book;
	else if ("W_KATAR" == str)
		value = ItemSubtype::Katar;
	else if ("W_REVOLVER" == str)
		value = ItemSubtype::Revolver;
	else if ("W_RIFLE" == str)
		value = ItemSubtype::Rifle;
	else if ("W_GATLING" == str)
		value = ItemSubtype::Gatling;
	else if ("W_SHOTGUN" == str)
		value = ItemSubtype::Shotgun;
	else if ("W_GRENADE" == str)
		value = ItemSubtype::Grenade;
	else if ("W_HUUMA" == str)
		value = ItemSubtype::Huuma;

	//For IT_AMMO:
	else if ("A_ARROW" == str)
		value = ItemSubtype::Arrow;
	else if ("A_DAGGER" == str)
		value = ItemSubtype::ThrowingDagger;
	else if ("A_BULLET" == str)
		value = ItemSubtype::Bullet;
	else if ("A_SHELL" == str)
		value = ItemSubtype::Shell;
	else if ("A_GRENADE" == str)
		value = ItemSubtype::GrenadeAmmo;
	else if ("A_SHURIKEN" == str)
		value = ItemSubtype::Shuriken;
	else if ("A_KUNAI" == str)
		value = ItemSubtype::Kunai;
	else if ("A_CANNONBALL" == str)
		value = ItemSubtype::Cannonball;
	else if ("A_THROWWEAPON" == str)
		value = ItemSubtype::ThrowWeapon;

	else
		throw std::runtime_error("Unknown item subtype \"" + std::string(str) + "\"");
	return *this;
}
} //namespace oro
