import { Node3D, Variant } from 'godot'
import { export_ } from 'godot.annotations'
import Interactor from '../interactor'
import ItemData from '../item_data'
import Inventory from '../inventory'

export default class Door extends Node3D {
	@export_(Variant.Type.TYPE_BOOL)
	readonly locked: boolean = false

	@export_(Variant.Type.TYPE_BOOL)
	readonly requires_key: boolean = false

	@export_(Variant.Type.TYPE_OBJECT, { class_: ItemData })
	readonly key_item?: ItemData

	open(interactor: Interactor): void {
		console.log('trying to open...')

		if (this.locked && this.requires_key) {
			console.log('this door requires a key')
			const inventory = Inventory.find_inventory(interactor.root_node)
			if (inventory != null && this.key_item != null && inventory.has(this.key_item)) {
				console.log('interactor has a', this.key_item.name)
			}
		} else {
			console.log('this door is opened some other way')
		}
	}
}
