package com.iqser.red.service.persistence.v1.internal.api.controller;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.iqser.red.service.persistence.management.v1.processor.service.FileStatusService;
import com.iqser.red.service.persistence.service.v1.api.internal.resources.StatusResource;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileModel;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
public class FileStatusInternalController implements StatusResource {

    private final FileStatusService fileStatusService;


    @Override
    public List<FileModel> getDossierStatus(@PathVariable(DOSSIER_ID_PARAM) String dossierId) {

        return fileStatusService.getDossierStatus(dossierId).stream().filter(f -> !f.isSoftOrHardDeleted()).collect(Collectors.toList());
    }


    @Override
    public List<FileModel> getSoftDeletedDossierStatus(@PathVariable(DOSSIER_ID_PARAM) String dossierId) {

        return fileStatusService.getDossierStatus(dossierId)
                .stream()
                .filter(f3 -> f3.getDeleted() != null && f3.getHardDeletedTime() == null)
                .sorted((f11, f21) -> f21.getDeleted().compareTo(f11.getDeleted()))
                .collect(Collectors.toList());
    }


    @Override
    public FileModel getFileStatus(@PathVariable(DOSSIER_ID_PARAM) String dossierId, @PathVariable(FILE_ID) String fileId) {

        return fileStatusService.getStatus(fileId);
    }

}
