import { ref } from 'vue'
import { defineStore } from 'pinia'
import { api } from 'boot/axios'
import type { FileStorage } from 'types/Storage'

export const useStoragesStore = defineStore('storages', () => {
  const storages = ref<FileStorage[]>([])
    
  async function getStorages () {
    const { data } = await api.get('/storage')
    storages.value = data.data as FileStorage[]
  }

  async function activate (id: number) {
    await api.post('/storage/' + id + '/activate')
  }

  async function remove (id: number) {
    await api.delete('/storage/' + id)
    await getStorages()
  }

  return {
    storages,
    getStorages,
    activate,
    remove
  }
})
