package com.izouma.immall.domain;

import com.izouma.immall.enums.VipType;
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.Where;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Map;

@Data
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Where(clause = "enabled = 1")
@ApiModel(value = "用户", description = "用户")
public class VipUser extends BaseEntity implements Serializable {
    @ApiModelProperty("用户Id")
    private Long userId;

/*    @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.DETACH})
    @JoinTable(
            name = "vip_authority",
            joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))},
            inverseJoinColumns = {@JoinColumn(name = "authority_name", referencedColumnName = "name", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))})
    @ExcelIgnore
    private Set<VipAuthority> vipAuthorities = new HashSet<>();*/

    @ApiModelProperty("会员类型")
    @Enumerated(EnumType.STRING)
    private VipType vipType;

    @ApiModelProperty("会员开始时间")
    private LocalDateTime startTime;

    @ApiModelProperty("会员结束时间")
    private LocalDateTime endTime;

    private String openId;

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

    private Long gitId;

    private Long gitCount;

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