# Hurry Curry! - a game about cooking
# Copyright (C) 2025 Hurry Curry! contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License only.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
class_name ItemFactory
extends Object

class ItemName:
	var raw: String
	var name: String
	var contents: PackedStringArray
	
	func _init(raw_name: String):
		raw = raw_name
		var c = Array(raw_name.split(":", false, 1))
		name = c[0]
		if c.size() == 1:
			contents = []
		elif not c[1].contains(":"):
			contents = c[1].split(",")
		else:
			contents = [c[1]] # Don't parse it, handle it in the item instead

static func produce(raw_name: String, owned_by: Node3D) -> Item:
	var name = ItemName.new(raw_name)
	var item: Item = produce_inner(name, owned_by)
	item.add_contents(name.contents)
	item.item_name = raw_name
	return item

static func produce_inner(item: ItemName, owned_by: Node3D) -> Item:
	match item.name:
		"bun": return Bun.new(owned_by)
		"cheese": return Cuttable.new(owned_by, preload("res://map/items/cheese.tscn"), Color("ffc844ff"))
		"cooked-noodles": return GenericItem.new(owned_by, preload("res://map/items/cooked_noodles.tscn"))
		"dirt": return GenericItem.new(owned_by, preload("res://map/items/dirt.tscn"))
		"sliced-bun": return GenericItem.new(owned_by, preload("res://map/items/sliced_bun.tscn"))
		"sliced-bun-top": return GenericItem.new(owned_by, preload("res://map/items/sliced_bun_top.tscn"))
		"sliced-bun-bottom": return GenericItem.new(owned_by, preload("res://map/items/sliced_bun_bottom.tscn"))
		"burned": return Burned.new(owned_by)
		"coconut": return GenericItem.new(owned_by, preload("res://map/items/coconut.tscn"))
		"dough": return GenericItem.new(owned_by, preload("res://map/items/dough.tscn"))
		"doughnut": return GenericItem.new(owned_by, preload("res://map/items/donut/glazed-donut.tscn"))
		"fish": return GenericItem.new(owned_by, preload("res://map/items/fish.tscn"))
		"flour": return GenericItem.new(owned_by, preload("res://map/items/flour.tscn"))
		"leek": return GenericItem.new(owned_by, preload("res://map/items/leek.tscn"))
		"mushroom": return GenericItem.new(owned_by, preload("res://map/items/mushroom.tscn"))
		"sliced-mushroom": return GenericItem.new(owned_by, preload("res://map/items/sliced_mushroom.tscn"))
		"noodles": return GenericItem.new(owned_by, preload("res://map/items/noodles.tscn"))
		"rolled-dough": return RolledDough.new(owned_by)
		"strawberry-mochi": return Mochi.new(owned_by, Color(.98, .70, .75))
		"nigiri": return GenericItem.new(owned_by, preload("res://map/items/nigiri.tscn"))
		"steak": return Cuttable.new(owned_by, preload("res://map/items/steak.tscn"), Color(0.74, 0.192, 0.22))
		"seared-steak": return GenericItem.new(owned_by, preload("res://map/items/seared_steak.tscn"))
		"patty": return GenericItem.new(owned_by, preload("res://map/items/patty.tscn"))
		"seared-patty": return GenericItem.new(owned_by, preload("res://map/items/seared_patty.tscn"))
		"rice": return GenericItem.new(owned_by, preload("res://map/items/rice.tscn"))
		"sliced-fish": return GenericItem.new(owned_by, preload("res://map/items/sliced_fish.tscn"))
		"strawberry": return GenericItem.new(owned_by, preload("res://map/items/strawberry.tscn"))
		"lettuce": return GenericItem.new(owned_by, preload("res://map/items/lettuce.tscn"))
		"tomato": return Cuttable.new(owned_by, preload("res://map/items/tomato.tscn"), Color(1., 0., 0.))
		"sliced-leek": return GenericItem.new(owned_by, preload("res://map/items/sliced_leek/sliced_leek.tscn"), 0.05)
		"sliced-lettuce": return GenericItem.new(owned_by, preload("res://map/items/sliced_lettuce.tscn"), 0.05)
		"sliced-cheese": return GenericItem.new(owned_by, preload("res://map/items/sliced_cheese.tscn"), 0.05)
		"sliced-tomato": return GenericItem.new(owned_by, preload("res://map/items/sliced_tomato.tscn"), 0.05)
		"potato": return Cuttable.new(owned_by, preload("res://map/items/potato.tscn"), Color("e1af5e"))
		"sliced-potato": return GenericItem.new(owned_by, preload("res://map/items/sliced_potato.tscn"))
		"dirty-plate":
			var plate = Plate.new(owned_by)
			plate.add_contents(["dirt"])
			return plate
		"pot": return Pot.new(owned_by)
		"basket": return Basket.new(owned_by)
		"pan": return Pan.new(owned_by)
		"pizza": return Pizza.new(owned_by)
		"foodprocessor": return FoodProcessor.new(owned_by)
		"glass": return Glass.new(owned_by)
		"plate": return Plate.new(owned_by)
		
		"unknown-order": return GenericItem.new(owned_by, preload("res://map/items/unknown_order.tscn"))

		_: return UnknownItem.new(owned_by, item.raw)
