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

import java.time.OffsetDateTime;
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 com.iqser.red.service.persistence.management.v1.processor.entity.download.DownloadStatusEntity;
import com.iqser.red.service.persistence.service.v1.api.shared.model.download.DownloadStatusValue;

public interface DownloadStatusRepository extends JpaRepository<DownloadStatusEntity, String> {

    List<DownloadStatusEntity> findAllByUserId(String userId);


    @Modifying
    @Query("update DownloadStatusEntity ds set ds.status = :status where ds.storageId = :storageId")
    void updateStatus(String storageId, DownloadStatusValue status);
    

    @Modifying
    @Query("update DownloadStatusEntity ds set ds.lastDownload = :lastDownload where ds.storageId = :storageId")
    void updateLastDownload(String storageId, OffsetDateTime lastDownload);

}
