package ru.kayashov.bar.model.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.List;

@Entity
@Table(name = "cocktail")
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CocktailEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String name;
    private String image;
    private String video;

    @OneToMany(mappedBy = "cocktail", cascade = CascadeType.REMOVE)
    private List<StopList> stopLists;

    @Column(columnDefinition = "text")
    private String instructions;

    @ManyToOne
    private CategoryEntity categoryEntity;
    @ManyToOne
    private AlcoholicEntity alcoholicEntity;
    @ManyToOne
    private GlassEntity glassEntity;

    @OneToMany(mappedBy = "cocktail", cascade = CascadeType.REMOVE)
    private List<ReceiptEntity> receipt;

    @ManyToMany
    @JoinTable(
            name = "cocktail_tags",
            joinColumns = @JoinColumn(name = "cocktail_id"),
            inverseJoinColumns = @JoinColumn(name = "tag_id")
    )
    private List<TagEntity> tags;

    @OneToMany(mappedBy = "cocktail", cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
    private List<Rating> rating;

    @Override
    public String toString() {
        return id + "-" + name + "-" + alcoholicEntity.getId();
    }
}
