import type { CharacterHair, CharacterType, Item, MapObject, Sprite, Tile } from '@/application/types'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useAssetManagerStore = defineStore('assetManager', () => {
  const tileList = ref<Tile[]>([])
  const selectedTile = ref<Tile | null>(null)

  const mapObjectList = ref<MapObject[]>([])
  const selectedMapObject = ref<MapObject | null>(null)

  const spriteList = ref<Sprite[]>([])
  const selectedSprite = ref<Sprite | null>(null)

  const characterTypeList = ref<CharacterType[]>([])
  const selectedCharacterType = ref<CharacterType | null>(null)

  const characterHairList = ref<CharacterHair[]>([])
  const selectedCharacterHair = ref<CharacterHair | null>(null)

  const itemList = ref<Item[]>([])
  const selectedItem = ref<Item | null>(null)

  function setTileList(tiles: Tile[]) {
    tileList.value = tiles
  }

  function setSelectedTile(tile: Tile | null) {
    selectedTile.value = tile
  }

  function setMapObjectList(objects: MapObject[]) {
    mapObjectList.value = objects
  }

  function setSelectedMapObject(object: MapObject | null) {
    selectedMapObject.value = object
  }

  function setSpriteList(sprites: Sprite[]) {
    spriteList.value = sprites
  }

  function setSelectedSprite(sprite: Sprite | null) {
    selectedSprite.value = sprite
  }

  function setCharacterTypeList(characterTypes: CharacterType[]) {
    characterTypeList.value = characterTypes
  }

  function setSelectedCharacterType(characterType: CharacterType | null) {
    selectedCharacterType.value = characterType
  }

  function setCharacterHairList(characterHair: CharacterHair[]) {
    characterHairList.value = characterHair
  }

  function setSelectedCharacterHair(characterHair: CharacterHair | null) {
    selectedCharacterHair.value = characterHair
  }

  function setItemList(items: Item[]) {
    itemList.value = items
  }

  function setSelectedItem(item: Item | null) {
    selectedItem.value = item
  }

  return {
    tileList,
    selectedTile,
    mapObjectList,
    selectedMapObject,
    spriteList,
    selectedSprite,
    characterTypeList,
    selectedCharacterType,
    characterHairList,
    selectedCharacterHair,
    itemList,
    selectedItem,
    setTileList,
    setSelectedTile,
    setMapObjectList,
    setCharacterTypeList,
    setSelectedMapObject: setSelectedMapObject,
    setSpriteList,
    setSelectedSprite,
    setSelectedCharacterType,
    setCharacterHairList,
    setSelectedCharacterHair,
    setItemList,
    setSelectedItem
  }
})
