package org.springblade.modules.api.response;

import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springblade.common.enums.OrderStateEnum;
import org.springblade.common.enums.YesOrNoEnum;
import org.springblade.modules.finance.entity.OrderGrouponGoods;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Data
public class UserOrderResponse {
    private Long orderId;
    private String orderNo;
    @JsonFormat(pattern = "MM/dd HH:mm")
    private Date grouponStartTime;
    @JsonFormat(pattern = "MM/dd HH:mm")
    private Date grouponEndTime;
    @JsonFormat(pattern = "MM/dd HH:mm")
    private Date takeStartTime;
    @JsonFormat(pattern = "MM/dd HH:mm")
    private Date takeEndTime;
    private String mainTitle;
    private String subTitle;
    private String selfTakeName;
    @ApiModelProperty(value = "自提点地址")
    private String address;
    @ApiModelProperty(value = "经度")
    private Double longitude;
    @ApiModelProperty(value = "纬度")
    private Double latitude;
    private String commander;
    private String phone;
    private String qrCode;
    private String pickupCode;
    private Integer orderState;
    private List<OrderGrouponGoods> goodsList;
    private String orderStateDesc;
    private Long grouponId;
    private Integer isArrive;
    private boolean canRefund;
    private boolean canRefundTwo;
    private boolean canReturnGoods;
    private BigDecimal paymentAmount;
    private LocalDateTime createTime;
    private Long afterSalesId;
    private Integer type;
    private Long orderGrouponGoodsId;
    private Integer afterSalesStatus;
    private String afterSalesStatusDesc;

//    public boolean isCanRefund() {
//        if (YesOrNoEnum.NO.getValue().equals(isArrive) && OrderStateEnum.WAIT_DELIVERY.getValue().equals(orderState) && DateUtil.date().after(takeStartTime)) {
//            return true;
//        } else if (OrderStateEnum.WAIT_DELIVERY.getValue().equals(orderState) &&
//                DateUtil.current() < grouponEndTime.getTime()) {
//            return true;
//        }
//        return canRefund;
//    }

    public String getOrderStateDesc() {
        if (this.orderState == null) {
            return orderStateDesc;
        } else {
            return OrderStateEnum.getNameByValue(this.orderState);
        }

    }
}
