package com.izouma.dingdong.domain;

import com.izouma.dingdong.domain.merchant.Merchant;
import com.izouma.dingdong.enums.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

@EqualsAndHashCode(callSuper = false)
@Data
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Where(clause = "enabled = 1")
@ApiModel(value = "订单表", description = "订单表")
public class OrderInfo extends BaseEntity {
    @ApiModelProperty(value = "用户ID", name = "userId")
    private Long userId;

    @ApiModelProperty(value = "用户昵称")
    private String nickname;

    //经度在前 纬度在后
    @ApiModelProperty(value = "用户地址经纬度",name = "location")
    private String location;

    @Enumerated(EnumType.STRING)
    @ApiModelProperty(value = "订单状态", name = "orderStatus")
    private OrderStatus status;

    //商家信息
    @ApiModelProperty(value = "商户ID", name = "merchantId")
    private Long merchantId;

//    @ManyToMany(fetch = FetchType.EAGER)
//    @ApiModelProperty(value = "商品ID", name = "goodsId")
//    private List<Goods> goods;

    @Enumerated(EnumType.STRING)
    @ApiModelProperty(value = "商家状态", name = "merchantStatus")
    private MerchantStatus merchantStatus;

    @ApiModelProperty(value = "备注", name = "remark")
    private String remark;

    //价格
    @ApiModelProperty(value = "包装价格", name = "packingPrice")
    private BigDecimal packingPrice;

    @ApiModelProperty(value = "配送费", name = "deliveryAmount")
    private BigDecimal deliveryAmount;

    @ApiModelProperty(value = "满减", name = "fullReduction")
    private BigDecimal fullReduction;

    @ApiModelProperty(value = "首单", name = "firstBuy")
    private BigDecimal firstBuy;

    @ApiModelProperty(value = "红包", name = "redBag")
    private BigDecimal redBag;

    @ApiModelProperty(value = "新用户", name = "newUser")
    private BigDecimal newUser;

    @ApiModelProperty(value = "总价", name = "totalAmount")
    private BigDecimal totalAmount;

//    @ApiModelProperty(value = "商品总价", name = "goodsAmount")
//    private BigDecimal goodsAmount;

    @ApiModelProperty(value = "实付金额", name = "realAmount")
    private BigDecimal realAmount;

    //使用优惠券
//    @ApiModelProperty(value = "是否使用优惠券", name = "isCoupon")
//    private Boolean isCoupon;

    @ApiModelProperty(value = "优惠券ID", name = "couponId")
    private Long userCouponId;


    //配送信息
/*    @ApiModelProperty(value = "骑手工号", name = "jobNumber")
    private String jobNumber;*/

    @ApiModelProperty(value = "骑手id", name = "riderId")
    private Long riderId;

    @Enumerated(EnumType.STRING)
    @ApiModelProperty(value = "骑手状态", name = "riderStatus")
    private RiderStatus riderStatus;


    //订单信息
    private String orderNo;

    @ApiModelProperty(value = "下单时间", name = "orderTime")
    private LocalDateTime orderTime;

    @ApiModelProperty(value = "用户地址Id",name = "addressId")
    private Long addressId;

    @ApiModelProperty(value = "配送地址", name = "userAddress")
    private String userAddress;

    @Enumerated(EnumType.STRING)
    @ApiModelProperty(value = "支付方式", name = "payMethod")
    private PayMethod payMethod;

    @Column(nullable = false)
    @ApiModelProperty(value = "取消订单", name = "cancel")
    private Boolean cancel = false;

    @Column(nullable = false)
    @ApiModelProperty(value = "已评价", name = "rated")
    private Boolean rated = false;

//    @ApiModelProperty(value = "商家接单时间", name = "merchantOrderTime")
//    private LocalDateTime merchantOrderTime;

//    @ApiModelProperty(value = "骑手接单时间", name = "riderOrderTime")
//    private LocalDateTime riderOrderTime;

    @ApiModelProperty(value = "用户收到时间", name = "userReceivedTime")
    private LocalDateTime userReceivedTime;

    @Column(nullable = false)
    private Boolean enabled = true;

    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinColumn(name = "orderInfoId")
    List<OrderGoodsSpec> orderGoodsSpecs;

    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.DETACH)
    @JoinColumn(name = "userId", insertable = false, updatable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    private User user;

    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.DETACH)
    @JoinColumn(name = "merchantId", insertable = false, updatable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    private Merchant merchant;

/*    @ManyToOne(fetch = FetchType.LAZY,cascade = CascadeType.DETACH)
    @JoinColumn(name = "merchantId", insertable = false, updatable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    private MerchantSettings merchantSettings;*/

    @Enumerated(EnumType.STRING)
    @ApiModelProperty(value = "取消订单原因", name = "reason")
    private RefundReason reason;

    @ApiModelProperty(value = "预计到达时间")
    private LocalDateTime timeOfArrival;

    //不显示的骑手列表
//    private String NotDisplayRiderIds;
    @ApiModelProperty(value = "期望送达时间段")
    private String expectDeliveryTime;

}
