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

let data = {
    "details": [
        {
            "id": 1634,
            "errorCode": "ER00001",
            "type": "KN",
            "description": "2:左侧动作故障,4:机械手移动到放货位置出错()",
            "files": [
                {
                    "id": 16,
                    "filePath": "/tmp/2016-08-16/1471329685902.jpg"
                },
                {
                    "id": 17,
                    "filePath": "/sku/0/0/427/1471329704482.jpg"
                },
                {
                    "id": 18,
                    "filePath": "/sku/0/0/426/1471330380712.jpg"
                }
            ],
        },
        {
            "id": 1,
            "errorCode": null,
            "type": "OP",
            "files": [
                {
                    "id": 16,
                    "filePath": "/tmp/2016-08-16/1471329685902.jpg"
                },
                {
                    "id": 17,
                    "filePath": "/sku/0/0/427/1471329704482.jpg"
                },
                {
                    "id": 18,
                    "filePath": "/sku/0/0/426/1471330380712.jpg"
                }
            ],
            "parentProblemName": "机械故障",
            "subProblemName": "其他问题111"
        }
    ],
    "employee": {
        "id": 5,
            "employeeName": "机器库管员",
            "headImageUrl": "/static/coupon/gounian/banner_hongbaotupian-3-14.jpg"
    },
    "taskIds": [
        155
    ]
}

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({},i,defaultDetailItem);
    });
    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;
    }
}