package at.procon.dip.migration.repository;

import at.procon.dip.migration.entity.LegacyTedMigrationRun;
import at.procon.dip.migration.entity.LegacyTedMigrationRunStatus;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface LegacyTedMigrationRunRepository extends JpaRepository<LegacyTedMigrationRun, UUID> {

    @Query("""
            select r
            from LegacyTedMigrationRun r
            where r.status in :statuses
            order by r.startedAt desc
            """)
    List<LegacyTedMigrationRun> findLatestByStatuses(@Param("statuses") Collection<LegacyTedMigrationRunStatus> statuses,
                                                     Pageable pageable);
}
