package nl.vpro.poel.domain;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Value;

import javax.persistence.*;
import java.util.Date;
import java.util.Objects;

/**
 * A user's predicted result.
 */
@Data
@EqualsAndHashCode(exclude = "id")
@NoArgsConstructor
@Entity
public class Prediction {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(nullable = false, updatable = false)
    private Long id;

    @ManyToOne(optional = false)
    private User user;

    @ManyToOne(optional = true)
    private Match match;

    @ManyToOne(optional = true)
    private Bonus bonus;

    @Embedded
    private MatchResult matchResult;

    @ManyToOne(optional = true)
    private BonusChoice answer;

    private boolean multiplier = false;

    public Prediction(User user, Match match) {
        this(user, match, null);
    }

    public Prediction(User user, Match match, MatchResult matchResult) {
        this(user, match, matchResult, false);
    }

    public Prediction(User user, Bonus bonus) {
        this(user, bonus, null);
    }

    public Prediction(User user, Bonus bonus, BonusChoice answer) {
        this(user, bonus, answer, false);
    }

    public Prediction(User user, Match match, MatchResult matchResult, boolean multiplier) {
        this.user = user;
        this.match = match;
        this.matchResult = matchResult;
        this.multiplier = multiplier;
    }

    public Prediction(User user, Bonus bonus, BonusChoice answer, boolean multiplier) {
        this.user = user;
        this.bonus = bonus;
        this.answer = answer;
        this.multiplier = multiplier;
    }

    public Date getStart() {
        Date startDate = null;
        if ( match != null ) {
            startDate = match.getStart();
        } else if ( bonus != null ) {
            startDate = bonus.getStart();
        }
        return startDate;
    }
}

@@ -112,67 +112,8 @@
 tor;
-%0Aimport org.springframework.beans.factory.annotation.Value;
 %0A%0Aim
@@ -164,34 +164,8 @@
 ate;
-%0Aimport java.util.Objects;
 %0A%0A/*
@@ -196,16 +196,170 @@
 result.%0A
+ *%0A * TODO: This class is currently (ab)used for predictions about either a Match or a Bonus question. There should be separate classes for these things.%0A
  */%0A@Dat
@@ -655,33 +655,16 @@
 anyToOne
-(optional = true)
 %0A    pri
@@ -696,33 +696,16 @@
 anyToOne
-(optional = true)
 %0A    pri
@@ -793,25 +793,8 @@
 oOne
-(optional = true)
 %0A   
@@ -1805,17 +1805,16 @@
     if (
- 
 match !=
@@ -1810,33 +1810,32 @@
 f (match != null
- 
 ) %7B%0A            
@@ -1883,17 +1883,16 @@
 lse if (
- 
 bonus !=
@@ -1896,17 +1896,16 @@
  != null
- 
 ) %7B%0A    

Use the TODO, Luke!