package com.psg.dlsysinfo.dl_sysinfo_server.repository;

import com.psg.dlsysinfo.dl_sysinfo_server.entity.CachedDeviceVuln;
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 org.springframework.data.jpa.repository.Modifying;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface CachedDeviceVulnRepository extends JpaRepository<CachedDeviceVuln, Long> {

    List<CachedDeviceVuln> findByDeviceId(Long deviceId);

    @Modifying
    @Transactional
    @Query("DELETE FROM CachedDeviceVuln c WHERE c.deviceId = :deviceId")
    void deleteByDeviceId(@Param("deviceId") Long deviceId);
}
