package com.dowstats.data.repositories

import com.dowstats.data.entities.building.Building
import com.dowstats.data.entities.Race
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.CrudRepository

interface BuildingRepository : CrudRepository<Building, Long>{
    @Query("""
        select b, a1, a2
        from Building b
            left join fetch ArmorType a1 on b.armorType.id = a1.id
            left join fetch ArmorType a2 on b.armorType2.id = a2.id
        where b.modId = :modId
        and (:race is null or b.race = :race)
        order by b.race.id desc
    """)
    fun findByModIdAndRace(modId: Long, race: Race?): List<Building>

    fun findByModIdAndFilename(modId: Long, fileName: String): Building?
}