package com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository;

import java.util.List;

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 com.iqser.red.service.persistence.management.v1.processor.entity.download.DownloadStatusReportEntity;

public interface DownloadStatusReportRepository extends JpaRepository<DownloadStatusReportEntity, String> {

    @Modifying(flushAutomatically = true, clearAutomatically = true)
    @Query("DELETE FROM DownloadStatusReportEntity d WHERE d.downloadStatusReportId.downloadStatusEntityStorageId = :downloadStatusEntityStorageId")
    void deleteByDownloadStatusReportId(@Param("downloadStatusEntityStorageId") String downloadStatusEntityStorageId);


    @Modifying(flushAutomatically = true, clearAutomatically = true)
    @Query("DELETE FROM DownloadStatusReportEntity d WHERE d.downloadStatusReportId.reportsTemplateId = :reportsTemplateId")
    void deleteByReportsTemplateId(@Param("reportsTemplateId") String reportsTemplateId);


    @Query("SELECT d FROM DownloadStatusReportEntity d WHERE d.downloadStatusReportId.reportsTemplateId = :reportsTemplateId")
    List<DownloadStatusReportEntity> findByReportsTemplateId(@Param("reportsTemplateId") String reportsTemplateId);

}
