import {
    POST_AD_ANSWER_REQUEST,
    POST_AD_ANSWER_SUCCESS,
    POST_AD_ANSWER_FAILURE,
    FETCH_ANSWER_REQUEST,
    FETCH_ANSWER_SUCCESS,
    FETCH_ANSWER_FAILURE,
    POST_MESSAGE_ANSWER_REQUEST,
    POST_MESSAGE_ANSWER_SUCCESS,
    POST_MESSAGE_ANSWER_FAILURE,
    FETCH_ANSWER_MESAGES_REQUEST,
    FETCH_ANSWER_MESAGES_SUCCESS,
    FETCH_ANSWER_MESAGES_FAILURE
} from "../types";

export function answer(state = {
}, action = {}) {
    switch (action.type) {
        case POST_AD_ANSWER_REQUEST:
            return {
                ...state,
                loading: true
            };
        case POST_AD_ANSWER_SUCCESS:
            return {
                ...state,
                ...action.res,
                loading: false
            };
        case POST_AD_ANSWER_FAILURE:
            return {
                ...state,
                errors: action.errors.response.data,
                loading: false
            };

        case FETCH_ANSWER_REQUEST:
            return {
                ...state,
                loading: true
            };
        case FETCH_ANSWER_SUCCESS:
            return {
                ...state,
                ...action.res,
                loading: false
            };
        case FETCH_ANSWER_FAILURE:
            return {
                ...state,
                errors: action.error,
                loading: false
            };
        case POST_MESSAGE_ANSWER_REQUEST:
            return {
                ...state,
                loadingMessage: true
            };
        case POST_MESSAGE_ANSWER_SUCCESS:
            return {
                ...state,
                messageSent: true,
                loadingMessage: false
            };
        case POST_MESSAGE_ANSWER_FAILURE:
            return {
                ...state,
                errors: action.errors.data,
                messageSent: false,
                loadingMessage: false
            };
        case FETCH_ANSWER_MESAGES_REQUEST: return {
            ...state,
            loadingMessage: true

        }
        case FETCH_ANSWER_MESAGES_FAILURE: return {
            ...state,
            loadingMessage: false,
            errors: action.errors.data,

        }
        case FETCH_ANSWER_MESAGES_SUCCESS: return {
            ...state,
            loadingMessage: false,
            messages:action.res.messages,
        }

        default:
            return state;
    }
}
