package digital.laboratory.platform.entrustment.convert;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSON;
import digital.laboratory.platform.entrustment.dto.EntrustMaterialCheckoutResultDTO;
import digital.laboratory.platform.entrustment.entity.EntrustMaterialCheckoutResult;
import digital.laboratory.platform.entrustment.vo.EntrustMaterialCheckoutResultVO;

/**
 * 托检材--检出定性定量结果信息 转换类
 */
public class EntrustMaterialCheckoutResultConvert {

    public static EntrustMaterialCheckoutResult dtoToEntity(EntrustMaterialCheckoutResultDTO dto) {
        if (dto == null) return null;
        EntrustMaterialCheckoutResult entrustMaterialCheckoutResult = new EntrustMaterialCheckoutResult();
        if (CollUtil.isNotEmpty(dto.getQualitativeResult())) {
            entrustMaterialCheckoutResult.setQualitativeResult(JSON.toJSONString(dto.getQualitativeResult()));
        } else {
            entrustMaterialCheckoutResult.setQualitativeResult(null);
        }
        if (CollUtil.isNotEmpty(dto.getMetaboliteResult())){
            entrustMaterialCheckoutResult.setMetaboliteResult(JSON.toJSONString(dto.getMetaboliteResult()));
        }
        entrustMaterialCheckoutResult.setQuantitativeResult(dto.getQuantitativeResult());
        entrustMaterialCheckoutResult.setOtherResult(dto.getOtherResult());
        entrustMaterialCheckoutResult.setCheckoutRemark(dto.getCheckoutRemark());
        return entrustMaterialCheckoutResult;

    }

    public static EntrustMaterialCheckoutResultVO entityToVO(EntrustMaterialCheckoutResult entity) {
        if (entity == null) return new EntrustMaterialCheckoutResultVO();
        EntrustMaterialCheckoutResultVO vo = new EntrustMaterialCheckoutResultVO();
        vo.setId(entity.getId());
        vo.setQualitativeResult(entity.getQualitativeResult());
        vo.setQuantitativeResult(entity.getQuantitativeResult());
        vo.setOtherResult(entity.getOtherResult());
        vo.setCheckoutRemark(entity.getCheckoutRemark());
        vo.setMetaboliteResult(entity.getMetaboliteResult());
        return vo;
    }

}
