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

// TODO: How to surpass cyclical dependency linting errors cleanly?
import {RootState} from '@/store'
import {state} from './state'
import {mutations, Mutations} from './mutations'
import type {PortaitState} from './state'

export {PortaitState}

export type PortaitStore<S = PortaitState> = Omit<VuexStore<S>, 'getters' | 'commit' | 'dispatch'>
  & {
  commit<K extends keyof Mutations, P extends Parameters<Mutations[K]>[1]>(
    key: K,
    payload: P,
    options?: CommitOptions
  ): ReturnType<Mutations[K]>
}
export const store: Module<PortaitState, RootState> = {
  state,
  mutations
  // TODO: With namespaced option turned on, having problem how to use dispatch with action types...
  // But without it, a bigger store might have clashes in namings
  // namespaced: true,
}
