import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { SetupStatus } from '../types'
import { configApi } from '../services/configApi'

export const useSetupStore = defineStore('setup', () => {
  const status = ref<SetupStatus | null>(null)
  const loading = ref(false)
  const currentStep = ref(0)

  async function checkStatus() {
    loading.value = true
    try {
      const { data } = await configApi.getSetupStatus()
      status.value = data
    } finally {
      loading.value = false
    }
  }

  function nextStep() {
    currentStep.value++
  }

  function prevStep() {
    if (currentStep.value > 0) currentStep.value--
  }

  return {
    status, loading, currentStep,
    checkStatus, nextStep, prevStep,
  }
})
