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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.wzj.soopin.member.domain.po.MemberAddress;
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.time.LocalDateTime;


@Data
@Schema(description = "商城订单请求体")
public class ManagerAftersaleOrderForm {

    @Schema(name = "id", description = "售后单号", required = true, implementation = Long.class)
    private Long id;

    @Schema(name = "orderSn", description = "订单号", required = true, implementation = String.class)
    private String orderSn;

    @Schema(name = "userPhone", description = "用户名称（手机号）", required = true, implementation = String.class)
    private String userPhone;

    @Schema(name = "status", description = "售后申请状态：0->待处理；1->退货中；2->已完成；3->已拒绝；4->用户取消", required = true, implementation = Integer.class)
    private Integer status;

    @Schema(name = "type", description = "售后类型：1->退款；2->退货退款", required = true, implementation = Integer.class)
    private Integer type;

    @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 QueryWrapper<Aftersale> toWrapper() {
        QueryWrapper<Aftersale> queryWrapper = new QueryWrapper<>();
        if (id != null) {
            queryWrapper.eq("id", id);
        }
        if (orderSn != null) {
            queryWrapper.eq("order_sn", orderSn);
        }
        if (userPhone != null) {
            queryWrapper.eq("user_phone", userPhone);
        }
        if (status != null) {
            queryWrapper.eq("status", status);
        }
        if (type != null) {
            queryWrapper.eq("type", type);
        }
        if (startTime != null) {
            queryWrapper.ge("create_time", startTime);
        }
        if (endTime != null) {
            queryWrapper.le("create_time", endTime);
        }
        queryWrapper.orderByDesc("id");
        return queryWrapper;
    }
}
