class_name Item extends Resource

@export var name: String
@export var description: String
@export var max_stack: int
@export var icon: Texture2D
@export var scene: PackedScene
@export var preview_scene: PackedScene

func _to_string() -> String:
    var icon_path = _resource_path_name(icon)
    var scene_path = _resource_path_name(scene)
    var preview_scene_path = _resource_path_name(preview_scene)

    return 'Item { name = "%s", description = "%s", max_stack = %s, icon = "%s", scene = "%s", preview_scene = "%s" }' % [name, description.substr(0, 24), max_stack, icon_path, scene_path, preview_scene_path]

func _resource_path_name(res: Resource) -> String:
    return res.resource_path if res != null else "None"

func _create(_scene: PackedScene) -> Option:
    if _scene != null and _scene.can_instantiate():
        return Option.some(_scene.instantiate())
    else:
        return Option.none

func create() -> Option:
    return _create(scene)

func create_preview() -> Option:
    return _create(preview_scene)


func combine(_with: Item) -> bool:
    return false

func use() -> bool:
    return false
