import * as ActionTypes from '../actionTypes'
import { MetadataDispatchTypes } from './types'
import { Event } from 'nostr-tools'

const initialState: Event | null = null

const reducer = (
  state = initialState,
  action: MetadataDispatchTypes
): Event | null => {
  switch (action.type) {
    case ActionTypes.SET_METADATA_EVENT:
      return {
        ...action.payload
      }

    case ActionTypes.RESTORE_STATE:
      return action.payload.metadata || null

    default:
      return state
  }
}

export default reducer
