package com.izouma.jiashanxia.domain;

import com.izouma.jiashanxia.enums.FlowType;
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 javax.persistence.*;

@Entity
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
@ApiModel(value = "套餐流水")
public class UserPackageFlow extends BaseEntity {
    private Long userId;

    @Enumerated(EnumType.STRING)
    private FlowType type;

    /*
    存储内容
    [{"goodsInfoId":11,"num":1},{"goodsInfoId":12,"num":1},{"goodsInfoId":13,"num":4}]
     */
    @Column(columnDefinition = "TEXT")
    private String content;

    @ApiModelProperty(value = "核销人")
    private Long writeOffUserId;

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

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