package org.pmiops.workbench.db.dao;

import java.util.List;
import java.util.Set;
import org.pmiops.workbench.db.model.DbCohortReview;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface CohortReviewDao extends JpaRepository<DbCohortReview, Long> {

  Set<DbCohortReview> findAllByCohortId(long cohortId);

  List<DbCohortReview> findAllByCdrVersionId(@Param("cdrVersionId") long cdrVersionId);

  DbCohortReview findCohortReviewByCohortIdAndCdrVersionId(
      @Param("cohortId") long cohortId, @Param("cdrVersionId") long cdrVersionId);

  DbCohortReview findCohortReviewByCohortReviewId(@Param("cohortReviewId") long cohortReviewId);

  @Query(
      value =
          "select * from cohort_review cr "
              + "join cohort c on (cr.cohort_id = c.cohort_id) "
              + "join workspace ws on (c.workspace_id = ws.workspace_id) "
              + "where ws.workspace_namespace = :ns "
              + "and ws.firecloud_name = :fcName "
              + "and ws.active_status = :status",
      nativeQuery = true)
  List<DbCohortReview> findByFirecloudNameAndActiveStatus(
      @Param("ns") String workspaceNamespace,
      @Param("fcName") String fcName,
      @Param("status") short status);

  @Query(
      value =
          "select * from cohort_review cr "
              + "join cohort c on (cr.cohort_id = c.cohort_id) "
              + "join workspace ws on (c.workspace_id = ws.workspace_id) "
              + "where ws.workspace_namespace = :ns "
              + "and ws.firecloud_name = :fcName "
              + "and cr.cohort_review_id = :cohortReviewId",
      nativeQuery = true)
  DbCohortReview findByNamespaceAndFirecloudNameAndCohortReviewId(
      @Param("ns") String workspaceNamespace,
      @Param("fcName") String fcName,
      @Param("cohortReviewId") long cohortReviewId);
}

@@ -443,97 +443,8 @@
 );%0A%0A
-  List%3CDbCohortReview%3E findAllByCdrVersionId(@Param(%22cdrVersionId%22) long cdrVersionId);%0A%0A
   Db
@@ -1254,612 +1254,7 @@
 us);
-%0A%0A  @Query(%0A      value =%0A          %22select * from cohort_review cr %22%0A              + %22join cohort c on (cr.cohort_id = c.cohort_id) %22%0A              + %22join workspace ws on (c.workspace_id = ws.workspace_id) %22%0A              + %22where ws.workspace_namespace = :ns %22%0A              + %22and ws.firecloud_name = :fcName %22%0A              + %22and cr.cohort_review_id = :cohortReviewId%22,%0A      nativeQuery = true)%0A  DbCohortReview findByNamespaceAndFirecloudNameAndCohortReviewId(%0A      @Param(%22ns%22) String workspaceNamespace,%0A      @Param(%22fcName%22) String fcName,%0A      @Param(%22cohortReviewId%22) long cohortReviewId);
 %0A%7D%0A

remove unused dao methods (#6690)