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

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.wzj.soopin.order.domain.entity.Aftersale;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

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

@Data
@Schema(description = "订单售后 查询 对象")
public class AftersaleBo {

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

    @Schema(description = "订单id 精确匹配")
    private Long orderId;

    @Schema(description = "退款金额 精确匹配")
    private BigDecimal returnAmount;

    @Schema(description = "售后类型：1：退款，2：退货退款 精确匹配")
    private Integer type;

    @Schema(description = "申请状态：0->待处理；1->退货中；2->已完成；3->已拒绝 精确匹配")
    private Integer status;

    @Schema(description = "处理时间 精确匹配")
    private LocalDateTime handleTime;

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

    @Schema(description = "原因 精确匹配")
    private String reason;

    @Schema(description = "描述 精确匹配")
    private String description;

    @Schema(description = "凭证图片，以逗号隔开 精确匹配")
    private String proofPics;

    @Schema(description = "处理备注 精确匹配")
    private String handleNote;

    @Schema(description = "处理人员 精确匹配")
    private String handleMan;

    @Schema(description = "退款流水号")
    private String orgTrace;

    @Schema(name = "startTime", description = "开始时间", required = true, implementation = LocalDateTime.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime startTime;

    @Schema(name = "endTime", description = "结束时间", required = true, implementation = LocalDateTime.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime endTime;

    public Wrapper<Aftersale> toWrapper() {
        return new LambdaQueryWrapper<Aftersale>()
            .eq(memberId != null, Aftersale::getMemberId, memberId)
            .eq(orderId != null, Aftersale::getOrderId, orderId)
            .eq(returnAmount != null, Aftersale::getReturnAmount, returnAmount)
            .eq(type != null, Aftersale::getType, type)
            .eq(status != null, Aftersale::getStatus, status)
            .eq(handleTime != null, Aftersale::getHandleTime, handleTime)
            .eq(quantity != null, Aftersale::getQuantity, quantity)
            .eq(reason != null && !reason.isEmpty(), Aftersale::getReason, reason)
            .eq(description != null && !description.isEmpty(), Aftersale::getDescription, description)
            .eq(proofPics != null && !proofPics.isEmpty(), Aftersale::getProofPics, proofPics)
            .eq(handleNote != null && !handleNote.isEmpty(), Aftersale::getHandleNote, handleNote)
            .eq(handleMan != null && !handleMan.isEmpty(), Aftersale::getHandleMan, handleMan)
            .eq(orgTrace != null && !orgTrace.isEmpty(), Aftersale::getOrgTrace, orgTrace)
            .between(startTime != null && endTime != null, Aftersale::getCreateTime, startTime, endTime)
            .ge(startTime != null && endTime == null, Aftersale::getCreateTime, startTime)
            .le(endTime != null && startTime == null, Aftersale::getCreateTime, endTime);
    }
}
