import { Store } from './store'
import { Inspector, EventPhase, InitConfig } from './types/core'


export const createClient = (store: Store): Inspector => {
  return {
    start: (config: InitConfig) => {
      store.dispatch({ type: 'RESET_APP' })
      store.dispatch.user.updateUser(config.user)
    },
    trace: (eventPhase: EventPhase) => {
      if (eventPhase.event.type === 'identify') {
        store.dispatch.user.updateUser({
          id: eventPhase.event.userId,
          traits: eventPhase.event.traits
        })
      }

      store.dispatch.events.traceEvent(eventPhase)
    }
  }
}
