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

import kr.co.accura.wtm.domain.teal.entity.TealVersion;
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;
import java.util.Optional;

@Repository
public interface TealVersionRepository extends JpaRepository<TealVersion, Long> {

    List<TealVersion> findByProject_IdOrderByVersionNumberDesc(Long projectId);

    @Query("SELECT MAX(v.versionNumber) FROM TealVersion v WHERE v.project.id = :projectId")
    Optional<Integer> findMaxVersionByProjectId(@Param("projectId") Long projectId);

    Optional<TealVersion> findByProject_IdAndStatus(Long projectId, String status);
}
