package de.htwsaar.webshop.repository.entities;


import de.htwsaar.webshop.model.SessionModel;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.UUID;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "Sessions")
public class Session {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @JoinColumn(name = "token", nullable = false)
    private UUID token;

    @Column(name = "timeout", nullable = false)
    private Long timeout;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "account_id", referencedColumnName = "id", nullable = false)
    private Account account;

    public SessionModel toModel() {
        return new SessionModel(token, timeout);
    }
}
