package cn.cecep.talroad.data.analyse.task.entity;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 *  站点设备信息
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class MainProductDeviceVo {

    private String id;

    private String proFacilityId;

    private String outletId;

    private String outletCode;

    public static List<MainProductDeviceVo> groupDevice(List<MainProductDeviceVo> mainProductDeviceVos){
        List<MainProductDeviceVo> groupDevice = new ArrayList<>();
        for (MainProductDeviceVo mainProductDeviceVo : mainProductDeviceVos) {
            String[] split = mainProductDeviceVo.getProFacilityId().split(",");
            List<MainProductDeviceVo> collect = Arrays.stream(split).map((s -> {
                MainProductDeviceVo mainProductDeviceVo1 = new MainProductDeviceVo();
                BeanUtils.copyProperties(mainProductDeviceVo, mainProductDeviceVo1);
                mainProductDeviceVo1.setProFacilityId(s);
                return mainProductDeviceVo1;
            })).collect(Collectors.toList());
            groupDevice.addAll(collect);
        }
        return groupDevice;
    }

    public static List<String> toJsonString(List<MainProductDeviceVo> mainProductDeviceVos){
        return mainProductDeviceVos.stream().map(MainProductDeviceVo::toJsonString).collect(Collectors.toList());
    }

    public static String toJsonString(MainProductDeviceVo mainProductDeviceVo){
        return JSONObject.toJSONString(mainProductDeviceVo);
    }

    public static List<MainProductDeviceVo> parse(List<String> jsonData){
        return jsonData.stream().map(MainProductDeviceVo::parse).collect(Collectors.toList());
    }

    public static MainProductDeviceVo parse(String jsonData){
        return JSONObject.parseObject(jsonData,MainProductDeviceVo.class);
    }


}
