package com.psg.dlsysinfo.dl_sysinfo_server.repository;

import com.psg.dlsysinfo.dl_sysinfo_server.entity.CachedInstalledSoftware;
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;

public interface CachedInstalledSoftwareRepository extends JpaRepository<CachedInstalledSoftware, Long> {

    List<CachedInstalledSoftware> findByDeviceId(Long deviceId);

    List<CachedInstalledSoftware> findBySoftwareName(String softwareName);

    @Transactional
    @Modifying
    @Query(value = "DELETE FROM cached_installed_software WHERE device_id = :deviceId", nativeQuery = true)
    void deleteByDeviceId(@Param("deviceId") Long deviceId);

}
