package com.kospo.talk.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.kospo.talk.payload.FavoriteDto;
import jakarta.persistence.*;
import lombok.*;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@JsonIgnoreProperties(ignoreUnknown = true)
@Table(name = "favorites")
public class Favorite {
    @EmbeddedId
    private FavoriteId id;

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "work_id", nullable = false, updatable = false, insertable = false)
    private Work work;

    public static Favorite to(FavoriteDto favoriteDto) {
        return Favorite.builder().id(FavoriteId.builder().sabun(favoriteDto.getSabun()).workId(favoriteDto.getWorkId()).build()).build();
    }
}