package com.interplug.qcast.batch;

import java.util.Arrays;
import java.util.List;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.job.builder.JobBuilder;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;

/** tasklet 방식의 Job을 생성하는 Configuration */
@Configuration
public class SampleOtherJobConfiguration {

  @Bean
  public Job sampleOtherJob(JobRepository jobRepository, Step sampleStep) {
    return new JobBuilder("sampleOtherJob", jobRepository).start(sampleStep).build();
  }

  @Bean
  public Step sampleOtherStep(
      JobRepository jobRepository, PlatformTransactionManager transactionManager) {
    return new StepBuilder("sampleOtherStep", jobRepository)
        .tasklet(
            (contribution, chunkContext) -> {
              List<String> items = Arrays.asList("Spring", "Batch", "Example");

              for (String item : items) {
                String processedItem = item.toUpperCase();
                System.out.println("Processing item: " + processedItem);
              }

              return RepeatStatus.FINISHED;
            },
            transactionManager)
        .build();
  }
}
