import {
	GET_FUJIFILM_ORDER_HISTORY,
	GET_FUJIFILM_ORDER_HISTORY_SUCCESS,
	GET_FUJIFILM_ORDER_HISTORY_ERROR,
	LOGOUT_SUCCESS,
} from '~/store/actionTypes';


export const initialState = {
	orders: [],
	meta: {
		loading: false,
		error: '',
	},
};

export const orderHistory = (state = initialState, { type, payload }) => {
	switch (type) {
		case GET_FUJIFILM_ORDER_HISTORY:
			return {
				...state,
				meta: {
					loading: true,
					error: '',
				},
			};
		case GET_FUJIFILM_ORDER_HISTORY_SUCCESS:
			return {
				...payload,
				meta: {
					loading: false,
					error: '',
				},
			};
		case GET_FUJIFILM_ORDER_HISTORY_ERROR:
		{
			const ret = {
				...initialState,
				meta: {
					loading: false,
					error: payload.error,
				},
			};
			return ret;
		}
		case LOGOUT_SUCCESS:
			return initialState;
		default:
			return state;
	}
};
