package com.dbnt.kcgfilemanager.service;

import com.dbnt.kcgfilemanager.config.LogStatus;
import com.dbnt.kcgfilemanager.model.FileInfo;
import com.dbnt.kcgfilemanager.repository.FileInfoRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.List;

@Service
@RequiredArgsConstructor
public class FileInfoService {
  private final FileInfoRepository fileInfoRepository;

  public void deleteFileInfoAll(int contentSeq){
    List<FileInfo> fileInfoList = fileInfoRepository.findByContentSeqOrderByFileSeqAsc(contentSeq);
    for(FileInfo fileInfo: fileInfoList){
      deleteStoredFile(new File(fileInfo.getSavePath(), fileInfo.getConversionName()));
    }
    fileInfoRepository.deleteAll(fileInfoList);
  }

  public void deleteStoredFile(File deleteFile){
    deleteFile.delete();
  }
}
