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.dossier.FileAttributeEntity;

public interface FileAttributesRepository extends JpaRepository<FileAttributeEntity, String> {

    @Modifying(flushAutomatically = true, clearAutomatically = true)
    @Query("DELETE FROM FileAttributeEntity f where f.fileAttributeId.fileAttributeConfigId = :fileAttributeConfigId")
    void deleteByFileAttributeConfigId(@Param("fileAttributeConfigId") String fileAttributeConfigId);


    @Modifying(flushAutomatically = true, clearAutomatically = true)
    @Query("DELETE FROM FileAttributeEntity f where f.fileAttributeId.fileId = :fileId")
    void deleteByFileId(@Param("fileId") String fileId);

    @Modifying(flushAutomatically = true, clearAutomatically = true)
    @Query("DELETE FROM FileAttributeEntity f where f.fileAttributeId.fileId in (:fileIds)")
    void deleteByFileIds(@Param("fileIds") List<String> fileIds);


    @Query("SELECT f FROM FileAttributeEntity f where f.fileAttributeId.fileId = :fileId")
    List<FileAttributeEntity> findByFileId(@Param("fileId") String fileId);

}
