package com.dowstats.data.entities.building

import com.dowstats.data.dto.controllers.WeaponSlotDto
import com.dowstats.data.entities.weapon.Weapon
import com.fasterxml.jackson.annotation.JsonIgnore
import jakarta.persistence.*
import java.io.Serializable


@Embeddable
class BuildingWeaponKey : Serializable {
    @Column(name = "building_id")
    var buildingId: Long? = null

    @Column(name = "weapon_id")
    var weaponId: Long? = null

    @Column(nullable = false)
    var hardpoint: Int = 0

    @Column(nullable = false)
    var hardpointOrder: Int = 0
}

@Entity
@Table(name = "buildings_weapons")
class BuildingWeapon {

    @EmbeddedId
    @JsonIgnore
    var buildingWeaponKey: BuildingWeaponKey? = null

    @ManyToOne
    @MapsId("buildingId")
    @JoinColumn(name = "building_id")
    @JsonIgnore
    var building: Building? = null

    @ManyToOne
    @MapsId("weaponId")
    @JoinColumn(name = "weapon_id")
    var weapon: Weapon? = null


    fun toWeaponSlotDto() = WeaponSlotDto(
        buildingWeaponKey!!.hardpoint,
        buildingWeaponKey!!.hardpointOrder,
        weapon?.toShortDto()!!
    )

}
