package com.dowstats.data.dto.controllers

import com.dowstats.data.dto.controllers.EntityCompressDtoObject.compressDto
import com.dowstats.data.entities.weapon.Weapon

data class WeaponUnitShortDto(
    val id: Long?,
    val filename: String,
    val name: String?,
    val units: Set<EntityCompressDto>,
    val sergeants: Set<SergeantUnitShortDto>,
    val buildings: Set<EntityCompressDto>
)

object WeaponUnitShortDtoObject{
    fun MutableSet<Weapon>.toShortDtoSet() =
        this.map {
            WeaponUnitShortDto(
                it.id!!,
                it.filename!!,
                it.name,
                it.unitsUse?.mapNotNull {
                    it.unit?.compressDto()
                }?.toSet() ?: emptySet(),
                it.sergeantsUse?.map {
                    SergeantUnitShortDto(
                        it.sergeant!!.id!!,
                        it.sergeant!!.filename!!,
                        it.sergeant!!.name,
                        it.sergeant!!.icon,
                        it.sergeant!!.unit!!.compressDto()
                    )
                }?.toSet() ?: emptySet(),
                it.buildingUse?.map { it.building!!.compressDto() }?.toSet() ?: emptySet()
            )
        }.toSet()
}