package com.spring.domain.email.batch;

import java.util.List;

import org.springframework.batch.core.Step;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.stereotype.Component;

import com.spring.domain.post.repository.PostRepository;
import com.spring.infra.batch.AbstractBatchTask;
import com.spring.infra.batch.BatchJobInfo;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
@BatchJobInfo(
    group = "${batch-info.email-send-batch.group}",
    jobName = "${batch-info.email-send-batch.job-name}",
    cronExpression = "${batch-info.email-send-batch.cron-expression}",
    description = "${batch-info.email-send-batch.description}"
)
@RequiredArgsConstructor
public class EmailSendBatch extends AbstractBatchTask {

    private final PostRepository postRepository;

    @Override
    protected List<Step> createSteps() {
        log.info("EmailSendBatch -> createSteps");
        return List.of(
                addStep("emailSendJobStep1", createTasklet()), 
                addStep("emailSendJobStep2", createSendTasklet())
                );
    }

    @Override
    protected Tasklet createTasklet() {
        log.info("EmailSendBatch -> createTasklet");
        return ((contribution, chunkContext) -> {
            postRepository.findAll();
            return RepeatStatus.FINISHED;
        });
    }

    private Tasklet createSendTasklet() {
        log.info("EmailSendBatch -> createSendTasklet");
        return ((contribution, chunkContext) -> RepeatStatus.FINISHED);
    }

}
