package dev.fyloz.trial.colorrecipesexplorer.model

import com.fasterxml.jackson.annotation.JsonIgnore
import java.util.*
import javax.persistence.*

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

    @JsonIgnore
    @ManyToOne
    val mix: Mix,

    @ManyToOne
    val material: Material,

    val quantity: Float
) : Model {
    constructor(mix: Mix, material: Material, quantity: Float) : this(null, mix, material, quantity)

    override fun equals(other: Any?): Boolean =
        other is MixMaterial && other.mix == mix && other.material == material && other.quantity == quantity

    override fun hashCode(): Int = Objects.hash(mix, material, quantity)
}

// ==== DSL ====
fun mixMaterial(
    id: Long? = null,
    mix: Mix = TODO(),
    material: Material = material(),
    quantity: Float = 0f,
    op: MixMaterial.() -> Unit = {}
) = MixMaterial(id, mix, material, quantity).apply(op)

