content: package com.example.demo.models;
  
  import java.time.LocalDateTime;
  import java.util.ArrayList;
  import java.util.List;
  
  import jakarta.persistence.AttributeOverride;
  import jakarta.persistence.CascadeType;
  import jakarta.persistence.Column;
  import jakarta.persistence.Embedded;
  import jakarta.persistence.EmbeddedId;
  import jakarta.persistence.Entity;
  import jakarta.persistence.JoinColumn;
  import jakarta.persistence.OneToMany;
  import jakarta.persistence.OrderBy;
  import jakarta.persistence.Table;
  
  import org.hibernate.annotations.CreationTimestamp;
  import org.hibernate.annotations.UpdateTimestamp;
  
  @Entity
  @Table(name = "products")
  public class Product {
      @EmbeddedId
      private ProductId id;
  
      @Embedded
      @AttributeOverride(name = "value", column = @Column(name = "category_id"))
      private CategoryId categoryId;
  
      @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
      @JoinColumn(name = "product_id")
      @OrderBy("id")
      private List<Image> images = new ArrayList<>();
  
      @Column(name = "name")
      private String name;
  
      @Embedded
      @AttributeOverride(name = "amount", column = @Column(name = "price"))
      private Money price;
  
      @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
      @JoinColumn(name = "product_id")
      @OrderBy("id")
      private List<ProductOption> options = new ArrayList<>();
  
      @Column(name = "description")
      private String description;
  
      @CreationTimestamp
      private LocalDateTime createdAt;
  
      @UpdateTimestamp
      private LocalDateTime updatedAt;
  
      public ProductId id() {
          return id;
      }
  
      public CategoryId categoryId() {
          return categoryId;
      }
  
      public int imageSize() {
          return images.size();
      }
  
      public Image image(int index) {
          return images.get(index);
      }
  
      public String name() {
          return name;
      }
  
      public Money price() {
          return price;
      }
  
      public int optionSize() {
          return options.size();
      }
  
      public ProductOption option(int index) {
          return options.get(index);
      }
  
      public String description() {
          return description;
      }
  }
  