import {
    REQUEST_PROFILE_INFO,
    RECIEVE_PROFILE_INFO,
    REQUEST_COUNTRIES,
    RECIEVE_COUNTRIES
} from '../../constants/profileSettingsConstants';

const moduleReducers = {};

moduleReducers[REQUEST_PROFILE_INFO] = (state, action) => {
    return Object.assign({}, state, {
        isLoading: action.isLoading
    });
};

moduleReducers[RECIEVE_PROFILE_INFO] = (state, action) => {
    return Object.assign({}, state, {
        profileInfo: action.profileInfo,
        isLoading: action.isLoading
    });
};

moduleReducers[REQUEST_COUNTRIES] = (state, action) => {
    return Object.assign({}, state, {
        areCountriesLoading: action.areCountriesLoading
    });
};

moduleReducers[RECIEVE_COUNTRIES] = (state, action) => {
    return Object.assign({}, state, {
        countries: action.countries,
        areCountriesLoading: action.areCountriesLoading
    });
};

const profileSettingsReducer = (state = {}, action) => {

    return moduleReducers[action.type] ? moduleReducers[action.type](state, action) : state;
};

export default profileSettingsReducer;
