class_name Town
extends Resource


enum Status {
	STATUS_POOR,
	STATUS_WEALTHY,
}

enum Size {
	SIZE_SMALL,
	SIZE_MEDIUM,
	SIZE_LARGE,
}

enum Workshop {
	WORKSHOP_NONE = 0,
	WORKSHOP_BLACKSMITH = 1 << 0,
	WORKSHOP_NUM = 1 << 1,
}

@export var name := "Nonamey"
@export var size := Size.SIZE_SMALL
@export var status := Status.STATUS_POOR
@export_flags("Blacksmith") var workshops := 0
@export var neighboring_towns: Array[Town]
@export var has_dimension_gate := false
@export var has_water := false
@export var possible_npcs: Array[PackedScene]


func status_to_string() -> String:
	match status:
		Status.STATUS_POOR:
			return "poor"
		Status.STATUS_WEALTHY:
			return "wealthy"
		_:
			assert(false, "tried to get string representation of invalid status")
			return "stupid"


func size_to_string() -> String:
	match size:
		Size.SIZE_SMALL:
			return "small"
		Size.SIZE_MEDIUM:
			return "medium"
		Size.SIZE_LARGE:
			return "large"
		_:
			assert(false, "tried to get string representation of invalid size")
			return "microscopic"


func workshop_to_string(workshop: Workshop) -> String:
	match workshop:
		Workshop.WORKSHOP_NONE:
			return "none"
		Workshop.WORKSHOP_BLACKSMITH:
			return "blacksmith"
		_:
			assert(false, "tried to get string representation of invalid workshop bit")
			return "buggyworld"


func workshop_list(capitalize := true, add_commas := true) -> String:
	var strings: PackedStringArray
	
	var current_bit: int = Workshop.WORKSHOP_NUM
	while current_bit > Workshop.WORKSHOP_NONE:
		if workshops & current_bit:
			strings.push_back(workshop_to_string(current_bit))
		
		current_bit >>= 1
	
	if capitalize:
		strings[0] = strings[0].to_pascal_case()
	
	if add_commas:
		return ", ".join(strings)
	else:
		return " ".join(strings)
