package com.dowstats.controllers

import com.dowstats.data.entities.Mod
import com.dowstats.data.entities.Race
import com.dowstats.data.repositories.ModRepository
import com.dowstats.data.repositories.RaceRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import jakarta.servlet.http.HttpServletRequest
import org.springframework.web.bind.annotation.PathVariable


@RestController
@RequestMapping("api/v1/races")
@EnableWebSecurity
class AvailableRacesController @Autowired constructor(
    val raceRepository: RaceRepository
) {

    @GetMapping("/{raceId}")
    fun getRace(@PathVariable raceId: String): Race? {
        return raceRepository.findById(raceId)
    }

    @GetMapping("/mod/{mod}")
    fun getModVersions(@PathVariable mod: Long): List<Race> {
        return raceRepository.findRacesByMod(mod)
    }

}
