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

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;

/**
 * 订单中所包含的商品 查询 对象
 *
 * @author zcc
 */
@Schema(description = "订单中所包含的商品 查询 对象")
@Data
public class OrderItemQuery {
    @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() {
        LambdaQueryWrapper<OrderItem> queryWrapper = new LambdaQueryWrapper<>();

        if (orderId != null) {
            queryWrapper.eq(OrderItem::getOrderId, orderId);
        }

        if (productId != null) {
            queryWrapper.eq(OrderItem::getProductId, productId);
        }

        if (outProductId != null && !outProductId.isEmpty()) {
            queryWrapper.eq(OrderItem::getOutProductId, outProductId);
        }

        if (skuId != null) {
            queryWrapper.eq(OrderItem::getSkuId, skuId);
        }

        if (outSkuId != null && !outSkuId.isEmpty()) {
            queryWrapper.eq(OrderItem::getOutSkuId, outSkuId);
        }

        if (productSnapshotId != null) {
            queryWrapper.eq(OrderItem::getProductSnapshotId, productSnapshotId);
        }

        if (skuSnapshotId != null) {
            queryWrapper.eq(OrderItem::getSkuSnapshotId, skuSnapshotId);
        }

        if (pic != null && !pic.isEmpty()) {
            queryWrapper.eq(OrderItem::getPic, pic);
        }

        if (productNameLike != null && !productNameLike.isEmpty()) {
            queryWrapper.like(OrderItem::getProductName, productNameLike);
        }

        if (salePrice != null) {
            queryWrapper.eq(OrderItem::getSalePrice, salePrice);
        }

        if (purchasePrice != null) {
            queryWrapper.eq(OrderItem::getPurchasePrice, purchasePrice);
        }

        if (quantity != null) {
            queryWrapper.eq(OrderItem::getQuantity, quantity);
        }

        if (productCategoryId != null) {
            queryWrapper.eq(OrderItem::getProductCategoryId, productCategoryId);
        }

        if (spData != null && !spData.isEmpty()) {
            queryWrapper.eq(OrderItem::getSpData, spData);
        }

        return queryWrapper;
    }
}
