package de.htwsaar.webshop.repository.entities;

import de.htwsaar.webshop.model.FarmImageModel;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.type.NumericBooleanConverter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
@Entity
@Table(name = "Farm_Images")
public class FarmImage {
    @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;

    @Convert(converter = NumericBooleanConverter.class)
    @Column(name = "standard", nullable = false)
    private boolean standard;

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