import { EducatorRegistrationActionTypes } from './educator.action.types'

const INITIAL_STATE = 
{
    inProgress: false,
    result: null,
    orderDetail: null,
    apiResponseStatus: -1,
    errorMessages: null,
    currentPage: 0
}

const educatorRegistrationReducer = (currentState = INITIAL_STATE, action) => {
    switch(action.type){

        case EducatorRegistrationActionTypes.RESET_STATE:
            return INITIAL_STATE

        case EducatorRegistrationActionTypes.POST_EDUCATOR_START:
            return {
                    ...currentState,
                    inProgress: true
                }
        
        
        
        case EducatorRegistrationActionTypes.POST_EDUCATOR_SUCCESS:            
               return {
                    ...currentState,
                    errorMessages: null,
                    ...action.payload,
                    inProgress: false,
                    currentPage: currentState.currentPage + 1
                }
            
        
        case EducatorRegistrationActionTypes.POST_EDUCATOR_FAILURE:
            const { message, apiResponseStatus } = action.payload
            return {
                    ...currentState,
                    result: null,
                    orderDetail: null,
                    errorMessages: message,
                    apiResponseStatus,                 
                    inProgress: false
                }
        
        case EducatorRegistrationActionTypes.POST_EDUCATOR_PAGE_CHANGE:
            return {
                ...currentState,
                currentPage: action.payload
            }
        case EducatorRegistrationActionTypes.POST_EDUCATOR_CLEAR_STATE:
            return {
                ...currentState,
                errorMessages: null
            }

        default:
            return currentState
    }

}

export default educatorRegistrationReducer