package cn.ey.biz.module.system.convert.code;

import cn.ey.biz.common.util.json.JsonUtils;
import cn.ey.biz.module.system.controller.admin.code.vo.CodeBlockingLevelVO;
import cn.ey.biz.module.system.controller.admin.code.vo.HistoryVO;
import cn.ey.biz.module.system.dal.dataobject.code.CodeBlockingLevelDO;
import cn.ey.biz.module.system.dal.dataobject.code.CodeBlockingLevelVarDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

@Mapper
public interface CodeBlockingLevelConvert {

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

    default CodeBlockingLevelDO rule2Do(CodeBlockingLevelVO.Rule rule) {

        CodeBlockingLevelDO codeBlockingLevelDO = new CodeBlockingLevelDO();
        codeBlockingLevelDO.setCountry(rule.getCountry());
        codeBlockingLevelDO.setRegion(rule.getRegion());
        codeBlockingLevelDO.setSl(rule.getSl());
        codeBlockingLevelDO.setRules(JsonUtils.toJsonString(rule.getCondition()));

        return codeBlockingLevelDO;
    }

    @Mapping(source = "id", target = "ver")
    @Mapping(source = "updater", target = "updateUser")
    @Mapping(source = "updateTime", target = "updateTime", dateFormat = "yyyy.MM.dd HH:mm:ss")
    @Mapping(source = "createTime", target = "createTime", dateFormat = "yyyy.MM.dd HH:mm:ss")
    HistoryVO do2History(CodeBlockingLevelVarDO bean);
}
