package studycave.studycaverestservice.model.test.question;

import com.fasterxml.jackson.annotation.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import studycave.studycaverestservice.model.test.Test;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include= JsonTypeInfo.As.PROPERTY, property = "type", visible = true )
@JsonSubTypes({
        @JsonSubTypes.Type(value = QuestionChoices.class, name="single-choice"),
        @JsonSubTypes.Type(value = QuestionChoices.class, name="multiple-choice"),
        @JsonSubTypes.Type(value = QuestionChoices.class, name="true-false"),
        @JsonSubTypes.Type(value = QuestionPairs.class, name="pairs"),
        @JsonSubTypes.Type(value = QuestionPuzzle.class, name="puzzle"),
        @JsonSubTypes.Type(value = QuestionGaps.class, name="gaps")
})
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@NoArgsConstructor
@AllArgsConstructor
public abstract class Question {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Getter
    @Setter
    private Long id;

    @Column(name="question")
    @JsonProperty("question")
    @Getter
    @Setter
    private String text;

    @Column(name="nr_question")
    @JsonProperty("nr")
    @Getter
    @Setter
    private int nrQuestion;
    //@NotNull
    @Getter
    @Setter
    protected String type;
    @Getter
    @Setter
    private int points;

    @ApiModelProperty(hidden = true)
    @ManyToOne
    @JoinColumn(name="id_test",referencedColumnName="id")
    @JsonBackReference
    @Getter
    @Setter
    private Test test;

    @OneToMany(fetch = FetchType.LAZY,mappedBy="question",cascade = CascadeType.ALL)
    @JsonManagedReference
    List<Answer> answers = new ArrayList<>();

    @Getter
    @Setter
    private int time;

    @Getter
    @Setter
    @Column(columnDefinition = "TINYINT(1)")
    private Boolean help = false;

}
