import { defineStore } from 'pinia'
import type { Character, Zone } from '@/types'

export const useZoneStore = defineStore('zone', {
  state: () => ({
    zone: null as Zone | null,
    characters: [] as Character[]
  }),
  actions: {
    setZone(zone: Zone | null) {
      this.zone = zone
    },
    setCharacters(characters: Character[]) {
      this.characters = characters
    },
    addCharacter(character: Character) {
      this.characters.push(character)
    },
    updateCharacter(character: Character) {
      const index = this.characters.findIndex((c) => c.id === character.id)
      if (index === -1) return
      this.characters[index] = character
    },
    removeCharacter(character: Character) {
      this.characters = this.characters.filter((c: Character) => c.id !== character.id)
    },
    reset() {
      this.zone = null
      this.characters = []
    }
  }
})
