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

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

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.DownloadRedactionFileStatusEntity;

public interface DownloadRedactionFileStatusRepository extends JpaRepository<DownloadRedactionFileStatusEntity, String> {

    List<DownloadRedactionFileStatusEntity> findAllByDownloadStorageId(String storageId);


    Optional<DownloadRedactionFileStatusEntity> findByDownloadStorageIdAndFileId(String storageId, String fileId);


    @Modifying
    @Query("update DownloadRedactionFileStatusEntity e set e.processingErrorCounter = :processingErrorCounter where e.downloadStorageId = :downloadStorageId and e.fileId = :fileId")
    void updateStatusErrorInfo(@Param("downloadStorageId") String downloadStorageId,
                               @Param("fileId") String fileId,
                               @Param("processingErrorCounter") Integer processingErrorCounter);


    @Modifying
    Integer deleteIfPresentByDownloadStorageId(String downloadStorageId);

}
