package cn.iocoder.yudao.module.system.convert.worklog;

import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.worklog.vo.loginstance.LogInstanceRespVO;
import cn.iocoder.yudao.module.system.controller.admin.worklog.vo.loginstance.LogInstanceSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.worklog.LogInstanceDO;
import com.alibaba.fastjson.JSONObject;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.time.format.DateTimeFormatter;

/**
 * 日志详情 Convert
 *
 * @author furongxin
 */
@Mapper
public interface LogInstanceConvert {

    LogInstanceConvert INSTANCE = Mappers.getMapper(LogInstanceConvert.class);

    LogInstanceDO convert(LogInstanceSaveReqVO bean);

    default LogInstanceRespVO convert(LogInstanceDO logInstanceDO) {

        LogInstanceRespVO logInstanceRespVO = BeanUtils.toBean(logInstanceDO, LogInstanceRespVO.class);
        if (logInstanceRespVO != null) {

            logInstanceRespVO.setFormVariables(JSONObject.toJSONString(logInstanceDO.getFormVariables()));
            logInstanceRespVO.setFileItems(JSONObject.toJSONString(logInstanceDO.getFileItems()));
            logInstanceRespVO.setCreateTime(logInstanceDO.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        }

        return logInstanceRespVO;
    }
}
