package org.jeecg.modules.adweb.api.vo;

import com.google.common.base.Splitter;

import lombok.Data;

import org.jeecg.modules.adweb.product.entity.AdwebProduct;

import java.util.List;
import java.util.Optional;

/**
 * @author wfansh
 */
@Data
public class ProductInfoVO {

    private Integer productId;

    private String productName;

    private String productNameZh;

    private String productImage;

    private List<String> productGalleryImage;

    private String categoryName;

    private String authorName;

    public static ProductInfoVO fromAdwebProduct(AdwebProduct adwebProduct) {
        ProductInfoVO productInfoVO = new ProductInfoVO();
        productInfoVO.setProductId(adwebProduct.getProductId());
        productInfoVO.setProductName(adwebProduct.getProductName());
        productInfoVO.setProductNameZh(adwebProduct.getProductNameZh());
        productInfoVO.setProductImage(adwebProduct.getProductImage());
        productInfoVO.setProductGalleryImage(
                Splitter.onPattern("[\\[\\],]")
                        .omitEmptyStrings()
                        .trimResults()
                        .splitToList(
                                Optional.ofNullable(adwebProduct.getProductGalleryImage())
                                        .orElse("")));
        productInfoVO.setCategoryName(adwebProduct.getCategoryName());
        productInfoVO.setAuthorName(adwebProduct.getAuthorName());

        return productInfoVO;
    }
}
