package com.brilliance.isc.transfer.transaction;

import com.brilliance.isc.bo.lg.NctfreStoreBo;
import com.brilliance.isc.transfer.IBaseStructMapper;
import com.brilliance.isc.transfer.model.*;
import com.brilliance.isc.vo.lg.NctfreStoreVo;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;


/**
 * Gitame Bo、Vo之间的转换处理类。如果有很复杂的函数，则可以用适配器模式重写
 */
@Mapper(componentModel = "spring",uses = {
        IGctMapper.class, IGitMapper.class,
        INitMapper.class, INctMapper.class, IOtherModMapper.class}
        )
public interface NctfreStructMapper extends IBaseStructMapper<NctfreStoreBo, NctfreStoreVo> {

    /**
     * 此行语句一定要写，StructMapper需要
     */
    NctfreStructMapper INSTANCE = Mappers.getMapper(NctfreStructMapper.class);

    /**
     * Vo转为Bo
     *
     * @param vo
     * @return 返回业务Bo
     */
    @Override
    NctfreStoreBo voTransferToBo(NctfreStoreVo vo);

    /**
     * Vo追加更新至Bo
     * 忽略oldgrp的复制
     * @param vo
     * @param bo
     */
    @Override
    @Mappings({
            @Mapping(target = "nidgrp",ignore = true),
            @Mapping(target = "ncdgrp",ignore = true)
    })
    void voUpdateToBo(NctfreStoreVo vo, @MappingTarget NctfreStoreBo bo);

    @AfterMapping
    default void afterUpdate(NctfreStoreVo vo, @MappingTarget NctfreStoreBo bo){
        if (vo.getNcdgrp().getRec() != null){
            bo.getNcdgrp().getRec().setDemstat(vo.getNcdgrp().getRec().getDemstat());
            bo.getNcdgrp().getRec().setNewexpdat(vo.getNcdgrp().getRec().getNewexpdat());
        }
        if (vo.getNcdgrp().getBlk() != null){
            bo.getNcdgrp().getBlk().setAddamtinf(vo.getNcdgrp().getBlk().getAddamtinf());
            bo.getNcdgrp().getBlk().setPresentdet(vo.getNcdgrp().getBlk().getPresentdet());
        }
        bo.getNcdgrp().setTmpint(vo.getNcdgrp().getTmpint());
        bo.getNcdgrp().setAwi(vo.getNcdgrp().getAwi());
    }

    /**
     * Bo转为Vo
     *
     * @param bo
     * @return 返回Vo
     */
    @Override
    NctfreStoreVo boTransferToVo(NctfreStoreBo bo);

    /**
     * bo追加更新至Bo
     *
     * @param bo
     * @param vo
     */
    @Override
    void boUpdateToVo(NctfreStoreBo bo, @MappingTarget NctfreStoreVo vo);
}
