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

import java.time.OffsetDateTime;
import java.util.List;

import org.springframework.stereotype.Service;

import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class DossierDeletionService {

    private final FileDeletionService fileDeletionService;
    private final DossierService dossierService;


    @Transactional
    public void undeleteDossier(String dossierId, List<String> relevantFileIds, OffsetDateTime dossierSoftDeleteTime) {

        relevantFileIds.forEach(fileId -> {
            fileDeletionService.undeleteFile(fileId, dossierSoftDeleteTime);
        });

        dossierService.undeleteDossier(dossierId);
    }


    @Transactional
    public void softDeleteDossier(String dossierId, List<String> relevantFileIds, OffsetDateTime softDeleteTime) {

        fileDeletionService.softDeleteFiles(relevantFileIds, softDeleteTime);
        dossierService.softDeleteDossier(dossierId, softDeleteTime);
    }


    @Transactional
    public void hardDeleteDossier(String dossierId, List<String> relevantFileIds) {

        fileDeletionService.hardDeleteFiles(dossierId, relevantFileIds);
        dossierService.hardDeleteDossier(dossierId);

    }


    public void hardDeleteFileDataAndIndexUpdates(String dossierId, List<String> fileIds) {

        fileDeletionService.hardDeleteFileDataAndIndexUpdates(dossierId, fileIds);

    }


    public void reindexUndeletedFiles(String dossierTemplateId, String dossierId, List<String> relevantFileIds) {

        this.fileDeletionService.reindexUndeletedFiles(dossierTemplateId, dossierId, relevantFileIds);
    }

}
