package com.dbnt.faisp.main.faStatistics.crackdownsStatus.repository;

import com.dbnt.faisp.main.faStatistics.crackdownsStatus.model.fishingBoat.Violation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

public interface ViolationRepository extends JpaRepository<Violation, Violation.ViolationId> {
    List<Violation> findByFbKey(Integer fbKey);
    Optional<Violation> findTopByFbKeyOrderByViolationKeyDesc(int fbKey);

    @Transactional
    @Modifying
    @Query("delete from Violation v where v.violationKey in :idList")
    void deleteAllByIdInQuery(@Param("idList") List<Integer> violationDeleteKeyList);
}
