package com.dowstats.data.entities.deathexplosion

import com.dowstats.data.dto.controllers.ArmorPiercingDto
import com.dowstats.data.dto.controllers.DeathExplosionDto
import jakarta.persistence.*
import java.math.BigDecimal


@Entity
@Table(name = "death_explosions")
class DeathExplosion {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    var id: Long? = null
    var globalChance: Double? = null
    var chance: Double? = null
    var minDamage: Double? = null
    var maxDamage: Double? = null
    var minDamageValue: Double? = null
    var moraleDamage: Double? = null
    var radius: Double? = null
    var throwForceMin: Double? = null
    var throwForceMax: Double? = null


    @OneToMany(mappedBy = "deathExplosion", cascade = [CascadeType.ALL])
    var explosionModifiers: MutableSet<DeathExplosionModifiers> = mutableSetOf()

    @OneToMany(mappedBy="deathExplosion", cascade = [(CascadeType.ALL)])
    var explosionPiercings: MutableSet<DeathExplosionArmorPiercing> = mutableSetOf()

    fun toDto(modId: Long): DeathExplosionDto = DeathExplosionDto(
            id!!,
            globalChance,
            chance,
            minDamage,
            maxDamage,
            minDamageValue,
            moraleDamage,
            radius,
            throwForceMin,
            throwForceMax,
            modId,
            explosionModifiers.map { it.toDto() },
            explosionPiercings.map { ArmorPiercingDto(it.armorType?.toDto(), it.piercingValue ?: BigDecimal.ZERO)  }
        )
}
