import { defineStore } from 'pinia'
import api from 'src/services/api'

export const useUserPermissionStore = defineStore('userPerm', {

  state: () => ({
    rows: [],
    loading: false,
    saving: false
  }),

  actions: {

    async fetch (id) {
      this.loading = true

      const res = await api.get(`/users/${id}/permissions`)
      this.rows = res.data || []

      this.loading = false
    },

    async save (id) {
      this.saving = true

      await api.post(`/users/${id}/permissions`, this.rows)

      this.saving = false
    }
  }
})
