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

import com.xunhong.erp.turbo.api.biz.dto.cmd.ProductCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.ProductUpdateCmd;
import com.xunhong.erp.turbo.biz.domain.entity.Product;
import com.xunhong.erp.turbo.biz.infrastructure.entity.ProductDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.NullValueCheckStrategy;

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

	@Mapping(target = "costList", source = "costDOList")
	Product toProduct(ProductDO productDO);

	@Mapping(target = "costDOList", ignore = true)
	@Mapping(target = "version", ignore = true)
	@Mapping(target = "updatedAt", ignore = true)
	@Mapping(target = "isDelete", ignore = true)
	@Mapping(target = "createdAt", ignore = true)
	ProductDO toProductDO(ProductCreateCmd productCreateCmd);

	@Mapping(target = "costDOList", ignore = true)
	@Mapping(target = "version", ignore = true)
	@Mapping(target = "updatedAt", ignore = true)
	@Mapping(target = "isDelete", ignore = true)
	@Mapping(target = "createdAt", ignore = true)
	void toProductDO(@MappingTarget ProductDO productDO, ProductUpdateCmd productUpdateCmd);
}

