import {
  Store as VuexStore,
  Module,
  CommitOptions,
  DispatchOptions,
} from 'vuex'

import { getters, Getters } from './getters'
import { mutations, Mutations, MutationTypes } from './mutations'
import { actions, Actions, ActionTypes } from './actions'

import { RootState } from '~/store/index'

import { AppLang } from '~/store/types'

interface State {
  lang: Map<string, AppLang>
}

const state: State = {
  lang: new Map(),
}

const data_module: Module<State, RootState> = {
  state,
  mutations,
  actions,
  getters,
}

export default data_module

type Store<S = State> = Omit<VuexStore<S>, 'commit' | 'getters' | 'dispatch' > & {
  commit<K extends keyof Mutations, P extends Parameters<Mutations[K]>[1]>(
    key: K,
    payload: P,
    options?: CommitOptions
  ): ReturnType<Mutations[K]>
} & {
  getters: {
    [K in keyof Getters]: ReturnType<Getters[K]>
  }
} & {
  dispatch<K extends keyof Actions>(
    key: K,
    payload: Parameters<Actions[K]>[1],
    options?: DispatchOptions
  ): ReturnType<Actions[K]>
}

export { State, ActionTypes, MutationTypes, Store }
