package dev.fyloz.trial.colorrecipesexplorer.model

import com.fasterxml.jackson.annotation.JsonIgnore
import dev.fyloz.trial.colorrecipesexplorer.model.validation.NullOrNotBlank
import java.util.*
import javax.persistence.*
import javax.validation.constraints.NotNull

@Entity
data class RecipeStep(
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    override val id: Long?,

    @JsonIgnore
    @ManyToOne
    val recipe: Recipe?,

    val message: String
) : Model {
    constructor(recipe: Recipe?, message: String) : this(null, recipe, message)

    override fun equals(other: Any?): Boolean =
        other is RecipeStep && other.recipe == recipe && other.message == message

    override fun hashCode(): Int = Objects.hash(recipe, message)
}


// ==== DSL ====
fun recipeStep(
    id: Long? = null,
    recipe: Recipe? = TODO(), // TODO change default when recipe DSL is done
    message: String = "message",
    op: RecipeStep.() -> Unit = {}
) = RecipeStep(id, recipe, message).apply(op)
