package space.nstart.pcp.complan.db.repository

import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param
import org.springframework.stereotype.Repository
import space.nstart.pcp.complan.db.entity.DynamicPlanIntervalEntity
import java.util.UUID

@Repository
interface DynamicPlanIntervalRepository : JpaRepository<DynamicPlanIntervalEntity, Long> {
    @Query(
        value = """
            select *
            from dynamic_plan_interval
            where run_id = :runId
            order by interval_order asc, id asc
            limit :limit offset :offset
        """,
        nativeQuery = true
    )
    fun findIntervalsByRunId(
        @Param("runId") runId: UUID,
        @Param("limit") limit: Int,
        @Param("offset") offset: Int
    ): List<DynamicPlanIntervalEntity>
}
