import { defineStore } from 'pinia'
import { getDict } from '@/hooks/web/useDictionaries'

const list = [
  { type: 'industryTreeData', apiFn: 'industryTreeData' },
  { type: 'areaTreeData', apiFn: 'areaTreeData' },
  { type: 'positionTreeData', apiFn: 'positionTreeData' },
  { type: 'positionData', params: {}, apiFn: 'positionData' },
  { type: 'menduner_industry_type', params: {}, apiFn: 'industryList' },
  { type: 'menduner_area_type', params: {}, apiFn: 'areaList' },
  { type: 'menduner_education_type' },
  { type: 'menduner_exp_type' },
  { type: 'system_user_sex' },
  { type: 'menduner_job_type' },
  { type: 'menduner_job_status' },
  { type: 'menduner_marital_status' },
  { type: 'menduner_pay_unit' },
  { type: 'menduner_financing_status' },
  { type: 'menduner_scale' },
  { type: 'menduner_hire_job_cv_status' },
  { type: 'menduner_education_system_type' },
  { type: 'menduner_skill_level' },
  { type: 'menduner_enterprise_type' },
  { type: 'menduner_pay_scope' }
]

export const useDictStore = defineStore('dict',
  {
    state: () => ({
      isSetDict: false
    }),
    actions: {
      getDictTypeData () {
        if (this.isSetDict) return
        this.isSetDict = true
        list.forEach(e => {
          getDict(e.type, e.params || null, e.apiFn)
        })
      }
    }
   },
  {
    persist: true
  }
)

