package com.izouma.dingdong.domain.user;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.izouma.dingdong.domain.BaseEntity;
import com.izouma.dingdong.domain.Coupon;
import com.izouma.dingdong.domain.User;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Where;

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

@Data
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Where(clause = "enabled = 1")
public class UserCoupon extends BaseEntity {
    @ApiModelProperty(value = "用户ID", name = "userId")
    private Long userId;

    private Long couponId;

    @ApiModelProperty(value = "是否已使用", name = "isUsed")
    private Boolean isUsed;

    @ApiModelProperty(value = "使用时间", name = "usedTime")
    private LocalDateTime usedTime;

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

    // @ApiModelProperty(value = "是否过期", name = "isExpired")
//    private Boolean isExpired;

    //用于限制手机号
    private String phone;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "couponId", insertable = false, updatable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    @JsonIgnore
    private Coupon coupon;

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