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

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wzj.soopin.order.domain.entity.OrderItem;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;

@Data
@Schema(description = "订单中所包含的商品 查询 对象")
public class OrderItemBo {
    @Schema(description = "订单id 精确匹配")
    private Long orderId;

    @Schema(description = "PRODUCT_ID 精确匹配")
    private Long productId;

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

    @Schema(description = "商品sku id 精确匹配")
    private Long skuId;

    @Schema(description = "sku编码 精确匹配")
    private String outSkuId;

    @Schema(description = "商品快照id 精确匹配")
    private Long productSnapshotId;

    @Schema(description = "sku快照id 精确匹配")
    private Long skuSnapshotId;

    @Schema(description = "展示图片 精确匹配")
    private String pic;

    @Schema(description = "PRODUCT_NAME 精确匹配")
    private String productNameLike;

    @Schema(description = "销售价格 精确匹配")
    private BigDecimal salePrice;

    @Schema(description = "采购价 精确匹配")
    private BigDecimal purchasePrice;

    @Schema(description = "购买数量 精确匹配")
    private Integer quantity;

    @Schema(description = "商品分类id 精确匹配")
    private Long productCategoryId;

    @Schema(description = "商品sku属性:[{\"key\":\"颜色\",\"value\":\"颜色\"},{\"key\":\"容量\",\"value\":\"4G\"}] 精确匹配")
    private String spData;

    public Wrapper<OrderItem> toWrapper() {
        return new LambdaQueryWrapper<OrderItem>()
            .eq(orderId != null, OrderItem::getOrderId, orderId)
            .eq(productId != null, OrderItem::getProductId, productId)
            .eq(outProductId != null && !outProductId.isEmpty(), OrderItem::getOutProductId, outProductId)
            .eq(skuId != null, OrderItem::getSkuId, skuId)
            .eq(outSkuId != null && !outSkuId.isEmpty(), OrderItem::getOutSkuId, outSkuId)
            .eq(productSnapshotId != null, OrderItem::getProductSnapshotId, productSnapshotId)
            .eq(skuSnapshotId != null, OrderItem::getSkuSnapshotId, skuSnapshotId)
            .eq(pic != null && !pic.isEmpty(), OrderItem::getPic, pic)
            .like(productNameLike != null && !productNameLike.isEmpty(), OrderItem::getProductName, productNameLike)
            .eq(salePrice != null, OrderItem::getSalePrice, salePrice)
            .eq(purchasePrice != null, OrderItem::getPurchasePrice, purchasePrice)
            .eq(quantity != null, OrderItem::getQuantity, quantity)
            .eq(productCategoryId != null, OrderItem::getProductCategoryId, productCategoryId)
            .eq(spData != null && !spData.isEmpty(), OrderItem::getSpData, spData);
    }
}
