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.WechatPaymentHistory;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;

/**
 * 微信订单表 查询 对象
 *
 * @author zcc
 */
@Schema(description = "微信订单表 查询 对象")
@Data
public class WechatPaymentHistoryQuery {
    @Schema(description = "payment_id 精确匹配")
    private String paymentId;

    @Schema(description = "用户 ID 精确匹配")
    private Long memberId;

    @Schema(description = "OPENID 精确匹配")
    private String openid;

    @Schema(description = "真实姓名，提现需要 精确匹配")
    private String realNameLike;

    @Schema(description = "标题|商品名称 精确匹配")
    private String title;

    @Schema(description = "订单号 支付时是payId 其他为orderId 精确匹配")
    private Long orderId;

    @Schema(description = "金额，单位分 精确匹配")
    private BigDecimal money;

    @Schema(description = "交易类型（1为支付  2为提现  3为退款） 精确匹配")
    private Integer opType;

    @Schema(description = "状态（0：未完成交易   1：完成关键交易） 精确匹配")
    private Integer paymentStatus;

    @Schema(description = "附加数据 精确匹配")
    private String attach;

    @Schema(description = "响应内容 精确匹配")
    private String responseBody;

    public Wrapper<WechatPaymentHistory> toWrapper() {
        LambdaQueryWrapper<WechatPaymentHistory> queryWrapper = new LambdaQueryWrapper<>();

        if (paymentId != null && !paymentId.isEmpty()) {
            queryWrapper.eq(WechatPaymentHistory::getPaymentId, paymentId);
        }

        if (memberId != null) {
            queryWrapper.eq(WechatPaymentHistory::getMemberId, memberId);
        }

        if (openid != null && !openid.isEmpty()) {
            queryWrapper.eq(WechatPaymentHistory::getOpenid, openid);
        }

        if (realNameLike != null && !realNameLike.isEmpty()) {
            queryWrapper.like(WechatPaymentHistory::getRealName, realNameLike);
        }

        if (title != null && !title.isEmpty()) {
            queryWrapper.eq(WechatPaymentHistory::getTitle, title);
        }

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

        if (money != null) {
            queryWrapper.eq(WechatPaymentHistory::getMoney, money);
        }

        if (opType != null) {
            queryWrapper.eq(WechatPaymentHistory::getOpType, opType);
        }

        if (paymentStatus != null) {
            queryWrapper.eq(WechatPaymentHistory::getPaymentStatus, paymentStatus);
        }

        if (attach != null && !attach.isEmpty()) {
            queryWrapper.eq(WechatPaymentHistory::getAttach, attach);
        }

        if (responseBody != null && !responseBody.isEmpty()) {
            queryWrapper.eq(WechatPaymentHistory::getResponseBody, responseBody);
        }

        return queryWrapper;
    }
}
