package org.brapi.test.BrAPITestServer.repository.germ;

import org.brapi.test.BrAPITestServer.model.entity.germ.SeedLotEntity;
import org.brapi.test.BrAPITestServer.repository.BrAPIRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

public interface SeedLotRepository extends BrAPIRepository<SeedLotEntity, String> {
	@Query(value = "SELECT s FROM SeedLotEntity s ORDER BY "
			+ "(SELECT COUNT(t) FROM SeedLotTransactionEntity t WHERE t.toSeedLot = s OR t.fromSeedLot = s) DESC, s.id ASC",
			countQuery = "SELECT COUNT(s) FROM SeedLotEntity s")
	Page<SeedLotEntity> findAllPrioritizeTransacted(Pageable pageReq);
}
