package kr.co.accura.wtm.domain.wbs.repository;

import kr.co.accura.wtm.domain.wbs.entity.WbsNode;
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 java.util.List;

@Repository
public interface WbsNodeRepository extends JpaRepository<WbsNode, Long> {

    List<WbsNode> findByWbsVersion_Id(Long wbsVersionId);

    @Query("SELECT n FROM WbsNode n WHERE n.wbsVersion.project.id = :projectId " +
            "AND n.wbsVersion.versionNumber = :versionNumber ORDER BY n.sortOrder")
    List<WbsNode> findByProjectIdAndVersion(@Param("projectId") Long projectId,
                                            @Param("versionNumber") int versionNumber);
}
