package ru.soune.nocopy.configuration;

import com.vrt.AudioFilePathProvider;
import com.vrt.fileprotection.FileProtector;
import com.vrt.fileprotection.audio.AudioLocalSearch;
import com.vrt.fileprotection.documents.DocumentLocalSearch;
import com.vrt.fileprotection.image.ImageLocalSearch;
import com.vrt.fileprotection.image.ImageUniqueCheck;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.util.Collections;

@Configuration
@EnableAutoConfiguration
@AllArgsConstructor
public class ApplicationConfig {

//    private final FileEntityRepository fileEntityRepository;

//    private final FileUtil fileUtil;

    @Bean
    PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Bean
    public com.vrt.
            NoCopyFileService noCopyFileService(
            FileProtector.FileProvider fileProvider,
            FileProtector.ProcessingListener processingListener,
            ImageUniqueCheck imageUniqueCheck,
            ImageLocalSearch imageLocalSearch,
            AudioLocalSearch audioLocalSearch,
            AudioFilePathProvider audioFilePathProvider,
            DocumentLocalSearch documentLocalSearch) {

//        List<FileProtector.FileInfo> initialFiles = loadProcessingFile();

        //TODO инициализация файлов при создании
        return new com.vrt.NoCopyFileService(
                Collections.emptyList(),
                fileProvider,
                processingListener,
                imageUniqueCheck,
                imageLocalSearch,
                audioLocalSearch,
                audioFilePathProvider,
                documentLocalSearch
        );
    }

//    private List<FileProtector.FileInfo> loadProcessingFile() {
//        List<FileEntity> byProtectionStatus =
//                fileEntityRepository.findByProtectionStatus(ProtectionStatus.PROCESSING);
//
//        return byProtectionStatus.stream().map(fileEntity ->
//                fileUtil.createFileInfo(fileEntity, null)).toList();
//    }
}

