package ru.soune.nocopy.service.file.impl;

import com.vrt.fileprotection.FileProtector;
import com.vrt.fileprotection.OperationResult;
import com.vrt.fileprotection.image.ImageUniqueCheck;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;
import ru.soune.nocopy.dto.file.SimilarFileDTO;
import ru.soune.nocopy.service.FileSimilarityService;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
public class ImageUniqueCheckImpl implements ImageUniqueCheck {

    private final FileSimilarityService fileSimilarityService;

    @Override
    public @NotNull OperationResult check(@NotNull FileProtector.FileInfo fileInfo) {
        String fileId = fileInfo.getId();
        List<SimilarFileDTO> duplicateByHammingDistance =
                fileSimilarityService.findDuplicateByHammingDistance(fileId, 3, 3, 4);

        if (duplicateByHammingDistance == null || duplicateByHammingDistance.isEmpty()) {
            return OperationResult.Companion.success();
        } else {
            return OperationResult.Companion.failure("Duplicate file");
        }
    }
}
