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

import com.vrt.fileprotection.FileProtector;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import ru.soune.nocopy.entity.file.ProtectionStatus;
import ru.soune.nocopy.service.file.FileEntityService;

@Slf4j
@Component
@AllArgsConstructor
public class NoCopyProcessingListenerImpl implements FileProtector.ProcessingListener {

    private final FileEntityService fileEntityService;

    @Override
    public void onStartProcessing(FileProtector.FileInfo fileInfo) {
        fileEntityService.changeProtectionStatus(ProtectionStatus.PROCESSING, fileInfo.getId());
    }

    @Override
    public void onProcessingFailed(FileProtector.FileInfo fileInfo) {
        fileEntityService.changeProtectionStatus(ProtectionStatus.FAILED, fileInfo.getId());
    }

    @Override
    public void onSavingFailed(FileProtector.FileInfo fileInfo) {
        fileEntityService.changeProtectionStatus(ProtectionStatus.FAILED_SAVE, fileInfo.getId());
    }

    @Override
    public void onFinish(FileProtector.FileInfo fileInfo) {
        fileEntityService.changeProtectionStatus(ProtectionStatus.PROTECTED, fileInfo.getId());;
    }
}
