package com.kamco.cd.kamcoback.common.utils.zip;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class CsvFileProcessor implements ZipEntryProcessor {

  @Override
  public boolean supports(String fileName) {
    return fileName.toLowerCase().endsWith(".csv");
  }

  @Override
  public void process(String fileName, InputStream is) throws IOException {
    try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
      br.lines()
          .forEach(
              line -> {
                String[] cols = line.split(",");
                // CSV 처리
                for (String col : cols) {
                  log.info(col); // TODO : 추후에 csv 파일 읽어서 작업 필요할 때 정의하기
                }
              });
    }
  }
}
