package com.wzj.soopin.goods.domain.bo;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wzj.soopin.goods.domain.entity.Product;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.dromara.common.core.domain.BaseBO;
import org.dromara.common.excel.annotation.Excel;

import java.math.BigDecimal;
import java.util.List;

@Data
@Schema(description = "商品信息 查询 对象")
public class ProductBo extends BaseBO<Product> {

    @Schema(description = "主键")
    private Long id;

    @Schema(description = "BRAND_ID 精确匹配")
    private Long brandId;

    @Schema(description = "CATEGORY_ID 精确匹配")
    private Long categoryId;

    @Schema(description = "查询分类及子分类id", hidden = true)
    private List<Long> categoryIds;

    @Schema(description = "商品编码 精确匹配")
    private String outProductId;

    @Schema(description = "NAME 模糊匹配")
    private String nameLike;

    @Schema(description = "上架状态：0->下架；1->上架 精确匹配")
    private Integer publishStatus;

    @Schema(description = "PRICE 精确匹配")
    private BigDecimal price;

    @Schema(description = "品牌名称 模糊匹配")
    private String brandNameLike;

    @Schema(description = "商品分类名称 模糊匹配")
    private String productCategoryNameLike;

    @Schema(description = "指定的商品ID列表")
    private List<Long> ids;

    @Schema(description = "审核状态")
    private String authFlag;

    @Schema(description = "店家手机号")
    private String contactPhone;

    @Schema(description = "NAME")
    @Excel(name = "NAME")
    private String name;

    @Schema(description = "主图")
    @Excel(name = "主图")
    private String pic;

    @Schema(description = "画册图片，连产品图片限制为5张，以逗号分割")
    @Excel(name = "画册图片，连产品图片限制为5张，以逗号分割")
    private String albumPics;



    @Schema(description = "排序")
    @Excel(name = "排序")
    private Integer sort;


    @Schema(description = "单位")
    @Excel(name = "单位")
    private String unit;

    @Schema(description = "商品重量，默认为克")
    @Excel(name = "商品重量，默认为克")
    private BigDecimal weight;

    @Schema(description = "商品销售属性，json格式")
    @Excel(name = "商品销售属性，json格式")
    private String productAttr;

    @Schema(description = "产品详情网页内容")
    @Excel(name = "产品详情网页内容")
    private String detailHtml;

    @Schema(description = "移动端网页详情")
    @Excel(name = "移动端网页详情")
    private String detailMobileHtml;

    @Schema(description = "品牌名称")
    @Excel(name = "品牌名称")
    private String brandName;

    @Schema(description = "商品分类名称")
    @Excel(name = "商品分类名称")
    private String productCategoryName;

    @Schema(description = "商品类型 1.团购;->2.拼团;3->秒杀")
    @Excel(name = "商品类型 1.团购;->2.拼团;3->秒杀")
    private Integer type;

    @Schema(description = "店铺id")
    @Excel(name = "店铺id")
    private String tenantId;


    @Schema(description = "销量")
    @Excel(name = "销量")
    private String sales;

    @Schema(description = "驳回原因")
    @Excel(name = "驳回原因")
    private String reasons;

    @Schema(description = "SKU列表")
    @Excel(name = "SKU列表")
    private List<SkuBo> skuList;
    public LambdaQueryWrapper<Product> toWrapper() {
        return new LambdaQueryWrapper<Product>()
            .eq(brandId != null, Product::getBrandId, brandId)
            .eq(categoryId != null, Product::getCategoryId, categoryId)
            .eq(outProductId != null && !outProductId.isEmpty(), Product::getOutProductId, outProductId)
            .eq(publishStatus != null, Product::getPublishStatus, publishStatus)
            .eq(price != null, Product::getPrice, price)
            .like(nameLike != null && !nameLike.isEmpty(), Product::getName, nameLike)
            .like(brandNameLike != null && !brandNameLike.isEmpty(), Product::getBrandName, brandNameLike)
            .like(productCategoryNameLike != null && !productCategoryNameLike.isEmpty(), Product::getProductCategoryName, productCategoryNameLike)
            .in(ids != null && !ids.isEmpty(), Product::getId, ids);
    }
}
