package samuelb.capripol;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
//Stored procedure to calculate a sightings value
@Entity
@NamedStoredProcedureQueries({
        @NamedStoredProcedureQuery(
                name = "sightingValue",
                procedureName = "CalculateSightingValue",
                parameters = {
                        @StoredProcedureParameter(
                                name = "baseRating",
                                type = BigDecimal.class,
                                mode = ParameterMode.IN),
                        @StoredProcedureParameter(
                                name = "userID",
                                type = Long.class,
                                mode = ParameterMode.IN),
                        @StoredProcedureParameter(
                                name = "focusID",
                                type = Long.class,
                                mode = ParameterMode.IN),
                        @StoredProcedureParameter(
                                name = "sightingValue",
                                type = BigDecimal.class,
                                mode = ParameterMode.OUT)})
})
/*
Entity representing a Sighting, has a Focus and 2 Users (sighter/sightee)
As of current a sighting has no location - could probably pull it from the
browser using Javascript, timezone could also be used to roughly determine location
 */
public class Sighting {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long sightingID;

    @ManyToOne(fetch = FetchType.EAGER, optional = false)
    @JoinColumn(name="sightedFocusID", nullable = false)
    private Focus focus;

    private LocalDateTime dateSighted;

    //institution?
    //private String location;

    @ManyToOne(fetch = FetchType.EAGER, optional = false)
    @JoinColumn(name="sighterUserID", nullable = false)
    private User sighter;

    private BigDecimal sighterUserRatingFocusID;

    private String sighterSighteeRelationship;

    private BigDecimal sightingValue;

    @ManyToOne(fetch = FetchType.EAGER, optional = false)
    @JoinColumn(name="sighteeUserID", nullable = false)
    private User sightee;

    public Sighting(){}

    public Sighting(Focus focus, LocalDateTime dateSighted, String location, User sighter, BigDecimal sighterUserRatingFocusID, String sighterSighteeRelationship, BigDecimal sightingValue, User sightee) {
        this.focus = focus;
        this.dateSighted = dateSighted;
        //this.location = location;
        this.sighter = sighter;
        this.sighterUserRatingFocusID = sighterUserRatingFocusID;
        this.sighterSighteeRelationship = sighterSighteeRelationship;
        this.sightingValue = sightingValue;
        this.sightee = sightee;
    }

    public Long getSightingID() {
        return sightingID;
    }

    public void setSightingID(Long sightingID) {
        this.sightingID = sightingID;
    }

    public Focus getFocus() {
        return focus;
    }

    public void setFocus(Focus focus) {
        this.focus = focus;
    }

    public LocalDateTime getDateSighted() {
        return dateSighted;
    }

    public void setDateSighted(LocalDateTime dateSighted) {
        this.dateSighted = dateSighted;
    }

//    public String getLocation() {
//        return location;
//    }
//
//    public void setLocation(String location) {
//        this.location = location;
//    }

    public User getSighter() {
        return sighter;
    }

    public void setSighter(User sighter) {
        this.sighter = sighter;
    }

    public BigDecimal getSighterUserRatingFocusID() {
        return sighterUserRatingFocusID;
    }

    public void setSighterUserRatingFocusID(BigDecimal sighterUserRatingFocusID) {
        this.sighterUserRatingFocusID = sighterUserRatingFocusID;
    }

    public String getSighterSighteeRelationship() {
        return sighterSighteeRelationship;
    }

    public void setSighterSighteeRelationship(String sighterSighteeRelationship) {
        this.sighterSighteeRelationship = sighterSighteeRelationship;
    }

    public BigDecimal getSightingValue() {
        return sightingValue;
    }

    public void setSightingValue(BigDecimal sightingValue) {
        this.sightingValue = sightingValue;
    }

    public User getSightee() {
        return sightee;
    }

    public void setSightee(User sightee) {
        this.sightee = sightee;
    }
}