import { getLevelList } from '@/apis/order'
import { SuccessResultCode, type Result, type TypeDescriptor } from '@cacp/ui'
import { defineStore } from 'pinia'
interface CoreState {
  isInited: boolean
  levelList: Array<TypeDescriptor>
}
export const useLevelStore = defineStore('level', {
  state: (): CoreState => ({
    isInited: false,
    levelList: []
  }),
  actions: {
    async initLevel() {
      if (!this.isInited) {
        const res: Result<Array<TypeDescriptor>> = await getLevelList()
        if (res.code === SuccessResultCode) {
          this.$patch({
            isInited: true,
            levelList: res.data
          })
        }
      }
    }
  }
})
