package com.xunhong.erp.turbo.biz.infrastructure.convert;

import com.xunhong.erp.turbo.api.biz.dto.common.OrderDealer;
import com.xunhong.erp.turbo.biz.infrastructure.entity.DealerSettingDO;
import com.xunhong.erp.turbo.biz.infrastructure.entity.OrderDealerDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueCheckStrategy;

/**
 * @author shenyifei
 */
@Mapper(componentModel = "spring", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
public interface OrderDealerConvert {

	@Mapping(target = "setting", expression = "java(this.toSettingDO(orderDealer))")
	@Mapping(target = "version", ignore = true)
	@Mapping(target = "updatedAt", ignore = true)
	@Mapping(target = "isDelete", ignore = true)
	@Mapping(target = "createdAt", ignore = true)
	OrderDealerDO toOrderDealerDO(OrderDealer orderDealer);

	default DealerSettingDO toSettingDO(OrderDealer orderDealer) {
		DealerSettingDO dealerSettingDO = new DealerSettingDO();
		dealerSettingDO.setEnableShare(orderDealer.getEnableShare());
		dealerSettingDO.setShareRatio(orderDealer.getShareRatio());
		dealerSettingDO.setFreightCostFlag(orderDealer.getFreightCostFlag());
		dealerSettingDO.setStrawMatCostFlag(orderDealer.getStrawMatCostFlag());
		dealerSettingDO.setIncludePackingFlag(orderDealer.getIncludePackingFlag());
		dealerSettingDO.setIncludeFreightFlag(orderDealer.getIncludeFreightFlag());
		dealerSettingDO.setEnableAccrualTax(orderDealer.getEnableAccrualTax());
		dealerSettingDO.setAccrualTaxRatio(orderDealer.getAccrualTaxRatio());
		dealerSettingDO.setEnableCompanyRebate(orderDealer.getEnableCompanyRebate());
		dealerSettingDO.setCompanyRebateRatio(orderDealer.getCompanyRebateRatio());
		dealerSettingDO.setShareAdjusted(orderDealer.getShareAdjusted());
		dealerSettingDO.setEnableLoss(orderDealer.getEnableLoss());
		dealerSettingDO.setLossAmount(orderDealer.getLossAmount());
		return dealerSettingDO;
	}

	@Mapping(target = "strawMatCostFlag", source = "setting.strawMatCostFlag")
	@Mapping(target = "shareRatio", source = "setting.shareRatio")
	@Mapping(target = "shareAdjusted", source = "setting.shareAdjusted")
	@Mapping(target = "lossAmount", source = "setting.lossAmount")
	@Mapping(target = "includePackingFlag", source = "setting.includePackingFlag")
	@Mapping(target = "includeFreightFlag", source = "setting.includeFreightFlag")
	@Mapping(target = "freightCostFlag", source = "setting.freightCostFlag")
	@Mapping(target = "enableShare", source = "setting.enableShare")
	@Mapping(target = "enableLoss", source = "setting.enableLoss")
	@Mapping(target = "enableCompanyRebate", source = "setting.enableCompanyRebate")
	@Mapping(target = "enableAccrualTax", source = "setting.enableAccrualTax")
	@Mapping(target = "companyRebateRatio", source = "setting.companyRebateRatio")
	@Mapping(target = "accrualTaxRatio", source = "setting.accrualTaxRatio")
	@Mapping(target = "createdByName", ignore = true)
	@Mapping(target = "createdBy", ignore = true)
	OrderDealer toOrderDealer(OrderDealerDO orderDealerDO);
}
