package de.htwsaar.webshop.repository.entities;

import de.htwsaar.webshop.model.ImageModel;
import jakarta.persistence.*;
import lombok.*;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
@Entity
@Table(name = "Images")
public class Image {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false, unique = true)
    private Long id;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "article_id", referencedColumnName = "id", nullable = false)
    private Article article;

    @Column(name = "base64", nullable = false)
    private String base64;

    public ImageModel toModel() {
        return new ImageModel(id, article.getUuid(), base64);
    }
}
