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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wzj.soopin.order.domain.entity.Order;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.dromara.common.core.domain.BaseBO;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Data
@Schema(description="订单表 查询 对象")
public class OrderBo extends BaseBO<Order> {

    @Schema(description ="MEMBER_ID  精确匹配")
    private Long memberId;

    @Schema(description ="订单编号  精确匹配")
    private String orderSn;

    @Schema(description ="租户id  精确匹配", hidden = true)
    private String tenantId;

    @Schema(description ="用户帐号  精确匹配")
    private String memberUsernameLike;

    @Schema(description ="订单总金额  精确匹配")
    private BigDecimal totalAmount;

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

    @Schema(description ="应付金额（实际支付金额）  精确匹配")
    private BigDecimal payAmount;


    @Schema(description ="支付方式：0->未支付；1->支付宝；2->微信  精确匹配")
    private Integer payType;

    /**
     *  订单状态枚举类型见{@link com.wzj.soopin.order.emum.OrderStatusEnum}
     */
    private Integer status;

    @Schema(description="是否处于退款状态")
    private Boolean aftersale;


    @Schema(description ="省份/直辖市  精确匹配")
    private String receiverProvince;

    @Schema(description ="城市  精确匹配")
    private String receiverCity;

    @Schema(description ="区  精确匹配")
    private String receiverDistrict;

    @Schema(description ="省份/直辖市id   精确匹配")
    private Long receiverProvinceId;

    @Schema(description ="城市id  精确匹配")
    private Long receiverCityId;

    @Schema(description ="区id  精确匹配")
    private Long receiverDistrictId;

    @Schema(description ="详细地址  精确匹配")
    private String receiverDetailAddress;

    @Schema(description ="订单备注  精确匹配")
    private String note;

    @Schema(description ="商家备注  精确匹配")
    private String MEMBER_ID;

    @Schema(description ="支付时间  精确匹配")
    private LocalDateTime paymentTime;


    @Schema(description ="创建订单开始时间  精确匹配")
    private LocalDateTime startTime;

    @Schema(description ="创建订单结束时间  精确匹配")
    private LocalDateTime endTime;

    @Schema(description = "订单类型：1->团购；2->拼团;3->秒杀；")
    private Integer type;

    @Schema(description = "提现状态：1->等待转账；2->转帐中;3->转账成功;4->转账失败")
    private Integer withdrawStatus;

    @Schema(description = "买家手机号")
    private String memberPhoneEncrypted;


    public LambdaQueryWrapper<Order> toWrapper() {
        return new LambdaQueryWrapper<Order>()
            .eq(memberId != null, Order::getMemberId, memberId)
            .eq(orderSn != null, Order::getOrderSn, orderSn)
            .eq(tenantId != null, Order::getTenantId, tenantId)
            .eq(payType != null, Order::getPayType, payType)
            .eq(status != null, Order::getStatus, status)
            .eq(aftersale != null, Order::getAftersale, aftersale)
            .between(startTime != null && endTime != null, Order::getCreateTime, startTime, endTime)
            .ge(startTime != null && endTime == null, Order::getCreateTime, startTime)
            .le(endTime != null && startTime == null, Order::getCreateTime, endTime);
    }

}
