package de.htwsaar.webshop.repository.entities;

import jakarta.persistence.*;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import lombok.*;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

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

    @Column(name = "uuid", nullable = false, unique = true)
    private UUID uuid;

    @Min(0)
    @Column(name = "stock", nullable = false)
    private Integer stock;

    @Min(0)
    @Column(name = "stock_expected", nullable = false)
    private Integer stockExpected;

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

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

    @Min(0)
    @Column(name = "price100", nullable = false)
    private Integer price100;

    @Min(0)
    @Max(100)
    @Column(name = "discount100", nullable = false)
    private Integer discount100;

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

    @OneToMany(mappedBy = "article", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
    private List<Review> reviews = new ArrayList<>();
}
