package de.votian.services.repository;

import de.votian.services.entity.TourArticle;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.math.BigDecimal;
import java.util.List;

public interface TourArticleRepository extends JpaRepository<TourArticle, Long> {

    List<TourArticle> findByJobId(Long jobId);

    List<TourArticle> findByJobIdAndTourSort(Long jobId, Integer tourSort);

    void deleteByJobId(Long jobId);

    @Query("SELECT COALESCE(SUM(ta.weight), 0) FROM TourArticle ta WHERE ta.jobId = :jobId")
    BigDecimal sumWeightByJobId(@Param("jobId") Long jobId);

    @Query("SELECT COALESCE(SUM(ta.packingPieces), 0) FROM TourArticle ta WHERE ta.jobId = :jobId")
    Integer sumPackingPiecesByJobId(@Param("jobId") Long jobId);
}
