package metier;

import jakarta.persistence.*;

import java.io.Serializable;
import java.util.List;

@Entity
public class Utilisateur implements Serializable {

    private int id;
    private String name;
    private List<Session> sessions;
    private String email;
    private String password;
    private List<Quizz> quizzs;

    public Utilisateur() {}

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(unique=true)
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @ManyToMany
    @JoinTable(
            name="utilisateur_session",
            joinColumns = @JoinColumn(name="utilisateur_id"),
            inverseJoinColumns = @JoinColumn(name = "session_pin")
    )
    public List<Session> getSessions() {
        return sessions;
    }

    public void setSessions(List<Session> sessions){
        this.sessions = sessions;
    }

    public String getPassword() {
        return this.password;
    }

    public void joinSession(Session session){
        this.sessions.add(session);
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @OneToMany(mappedBy = "utilisateur")
    public List<Quizz> getQuizzs() {
        return quizzs;
    }

    public void setQuizzs(List<Quizz> quizzs) {
        this.quizzs = quizzs;
    }
}