package com.example.demo.entities;







import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.util.Date;
import java.util.Set;

@Entity
@Table(name="cart_items")
@Getter
@Setter
public class CartItem {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "cart_item_id")
    private Long id;

    @ManyToMany
    @JoinTable(
            name = "excursion_cartitem",
            joinColumns = @JoinColumn(name = "cart_item_id"),
            inverseJoinColumns = @JoinColumn(name = "excursion_id")
    )
    private Set<Excursion> excursions;

    // WARNING: Do not add cascade here as Excursion entities are existing reference data and should not be cascaded from CartItem.

    @ManyToOne
    @JoinColumn(name = "cart_id")
    private Cart cart;


    @CreationTimestamp
    @Column(name = "create_date")
    private Date create_date;

    @UpdateTimestamp
    @Column(name = "last_update")
    private Date last_update;


    @ManyToOne
    @JoinColumn(name = "vacation_id")
    private Vacation vacation;

    // WARNING: Do not add cascade here (e.g., CascadeType.ALL) as it will cause Vacation and Excursion entities to be duplicated during checkout.
    // Vacation and Excursion are existing reference data and should not be cascaded from CartItem.

}
