package com.izouma.jiashanxia.domain;

import com.izouma.jiashanxia.annotations.Searchable;
import com.izouma.jiashanxia.enums.OrderInfoStatus;
import com.izouma.jiashanxia.enums.PayMethod;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;

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

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Where(clause = "del = 0")
@ApiModel(value = "订单")
public class OrderInfo extends BaseEntity {

    private Long userId;

    @ApiModelProperty(value = "支付方式")
    private PayMethod payMethod;

    @ApiModelProperty(value = "支付时间")
    private LocalDateTime paidAt;

    @Enumerated(EnumType.STRING)
    @ApiModelProperty(value = "订单状态")
    private OrderInfoStatus status;

    @ApiModelProperty(value = "数量")
    private Integer num;

    @Searchable
    @ApiModelProperty(value = "订单号")
    private String orderNumber;

    @ApiModelProperty(value = "交易单号")
    private String transactionId;

    @Searchable
    @ApiModelProperty(value = "名称")
    private String name;

    @ApiModelProperty(value = "充值套餐")
    private Long packageId;

    @ApiModelProperty(value = "价钱")
    private BigDecimal price;

//    @ApiModelProperty(value = "用户端是否显示")
//    private Boolean isShow;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "userId", insertable = false, updatable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    @NotFound(action = NotFoundAction.IGNORE)
    private User user;

}
