package cn.newfeifan.mall.module.product.convert.skuapply;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.newfeifan.mall.module.product.dal.dataobject.skuapply.SkuApplyDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.*;
import java.util.stream.Collectors;


/**
 * 商品 SKUApply Convert
 *
 * @author 非繁源码
 */
@Mapper
public interface SkuApplyConvert {

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

    default String buildPropertyKey(SkuApplyDO bean) {
        if (CollUtil.isEmpty(bean.getProperties())) {
            return StrUtil.EMPTY;
        }
        List<SkuApplyDO.Property> properties = new ArrayList<>(bean.getProperties());
        properties.sort(Comparator.comparing(SkuApplyDO.Property::getValueId));
        return properties.stream().map(m -> String.valueOf(m.getValueId())).collect(Collectors.joining());
    }


}
