package com.cf.imes.module.system.convert.machine;

import com.alibaba.fastjson.JSON;
import com.cf.imes.module.system.controller.admin.machine.vo.CuttingRespVO;
import com.cf.imes.module.system.controller.admin.machine.vo.CuttingSaveReqVO;
import com.cf.imes.module.system.dal.dataobject.machine.MachineDO;
import com.cf.imes.module.system.dal.dataobject.machine.MachineLimitDO;

import java.util.Objects;

/**
 * @author Beal
 */
public class MachineConvert {

    public static MachineDO convert(CuttingSaveReqVO createReqVO) {
       return MachineDO.builder()
                .machineType(createReqVO.getMachineType())
                .name(createReqVO.getName())
                .id(createReqVO.getId())
                .labelId(createReqVO.getLabelId())
                .setting(createReqVO.getMachineSettingDO().toJSONString())
               .build();

    }

    public static CuttingRespVO convert(MachineDO machineDO, MachineLimitDO machineLimitDO) {
        return CuttingRespVO.builder()
                .id(machineDO.getId())
                .machineSettingDO(JSON.parseObject(machineDO.getSetting()))
                .createTime(machineDO.getCreateTime())
                .labelId(machineDO.getLabelId())
                .name(machineDO.getName())
                .machineType(machineDO.getMachineType())
                .labelId(machineDO.getLabelId())
                .showAutoNotePrinter(Objects.isNull(machineLimitDO)? Boolean.FALSE: machineLimitDO.getShowAutoNotePrinter())
                .showDualWorkstation(Objects.isNull(machineLimitDO)? Boolean.FALSE: machineLimitDO.getShowDualWorkstation())
                .showPriorFacing(Objects.isNull(machineLimitDO)? Boolean.FALSE: machineLimitDO.getShowPriorFacing())
                .build();

    }
}
