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

import com.vrt.fileprotection.FileProtector;
import com.vrt.fileprotection.documents.DocumentLocalSearch;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.stereotype.Service;
import ru.soune.nocopy.entity.file.FileEntity;
import ru.soune.nocopy.repository.FileEntityRepository;
import ru.soune.nocopy.util.FileUtil;

@Slf4j
@Service
@RequiredArgsConstructor
public class DocumentLocalSearchImpl implements DocumentLocalSearch {

    private final FileUtil fileUtil;

    private final FileEntityRepository fileEntityRepository;

    @Override
    public @Nullable FileProtector.FileInfo findByIds(@NotNull String ownerId, @NotNull String fileId) {
        FileEntity fileEntity = fileEntityRepository.findByIdAndUserId(fileId, Long.valueOf(ownerId));
        FileProtector.FileInfo fileInfo = fileUtil.createFileInfo(fileEntity, null);
        log.info("fileInfo: {}", fileInfo);
        log.info("fileInfo: {}", fileInfo);
        log.info("fileInfo: {}", fileInfo);
        log.info("fileInfo: {}", fileInfo);
        log.info("fileInfo: {}", fileInfo);
        log.info("fileInfo: {}", fileInfo);
        log.info("fileInfo: {}", fileInfo);
        log.info("fileInfo: {}", fileInfo);
        log.info("fileInfo: {}", fileInfo);
        log.info("fileInfo: {}", fileInfo);
        log.info("fileInfo: {}", fileInfo);
        log.info("fileInfo: {}", fileInfo);
        log.info("fileInfo: {}", fileInfo);
        log.info("fileInfo: {}", fileInfo);
        log.info("fileInfo: {}", fileInfo);
        log.info("fileInfo: {}", fileInfo);
        log.info("fileInfo: {}", fileInfo);
        log.info("fileInfo: {}", fileInfo);

        return fileInfo;
    }
}
