package com.dowstats.data.entities.sergant

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


@Embeddable
class SergeantWeaponKey : Serializable {
    @Column(name = "sergeant_id")
    var sergeantId: 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 = "sergeants_weapons")
class SergeantWeapon {

    @EmbeddedId
    @JsonIgnore
    var sergeantWeaponKey: SergeantWeaponKey? = null

    @ManyToOne
    @MapsId("sergeantId")
    @JoinColumn(name = "sergeant_id")
    @JsonIgnore
    var sergeant: Sergeant? = null

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

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