class_name ItemAction
const DialogueAction = preload("res://cutscene/dialogue/DialogueAction.gd")

# Passed as extra_game_states so {{item_name}} and {{quantity}} resolve in the .dialogue file.
class ItemDialogueState:
  var item_name:String
  var quantity:int
  func _init(name:String, qty:int) -> void:
    item_name = name
    quantity = qty

static var PICKUP_DIALOGUE:DialogueResource = preload("res://dialogue/item/pickup.dialogue")

static func itemGetCallable(params:Dictionary) -> int:
  assert(params.has('stack'))
  var stack:ItemStack = params['stack']
  PARTY.BACKPACK.addStack(stack)

  var state = ItemDialogueState.new(Item.getItemName(stack.item), stack.quantity)
  var dialogueParams:Dictionary = DialogueAction.getDialogueCallable(PICKUP_DIALOGUE, 'start', [state])
  dialogueParams['position'] = Cutscene.CUTSCENE_ADD_NEXT
  params['cutscene'].addCallable(dialogueParams)
  return Cutscene.CUTSCENE_CONTINUE

static func getItemCallable(itemStack:ItemStack) -> Dictionary:
  return {
    'function': itemGetCallable,
    'stack': itemStack,
  }
