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

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import ru.soune.nocopy.entity.file.FileEntity;
import ru.soune.nocopy.entity.file.permission.PermissionType;
import ru.soune.nocopy.repository.FileEntityRepository;

import java.io.FileNotFoundException;

@Service
@RequiredArgsConstructor
public class FileAccessService {

    private final FileEntityRepository fileEntityRepository;

    public void changePermission(String fileId, PermissionType type, boolean allowed) throws FileNotFoundException {
        FileEntity file = fileEntityRepository.findById(fileId)
                .orElseThrow(() -> new FileNotFoundException(fileId));
        file.setPermission(type, allowed);

        fileEntityRepository.save(file);
    }
}
