import actionTypes from '../actiontype/trouble';


const dealTroubleList = (data)=>{
    let defaultInfo = {
        details: [],
    };
    let defaultDetailItem = {
        isExistProblem : 0,
        imagesFileId : "",
        explanation : ""
    };
    let info = Object.assign({},defaultInfo,data);
    info.details = info.details.map((i)=>{
        return Object.assign({},defaultDetailItem,i);
    });
    return info;
};

const saveTroubles = (content,data)=>{
    let newData = dealTroubleList(data);
    return Object.assign({},content,newData);
};

export default function(state={}, action) {
    switch (action.type) {
        case actionTypes.SAVETROUBLELIST:
            return saveTroubles(state,action.data);
        default:
            return state;
    }
}