package com.kamco.cd.kamcoback.scheduler;

import com.kamco.cd.kamcoback.scheduler.service.MapSheetMngFileJobService;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class MapSheetMngFileJobController {

  private final MapSheetMngFileJobService mapSheetMngFileJobService;

  // 현재 상태 확인용 Getter
  @Getter private boolean isSchedulerEnabled = false;
  @Getter private int mngSyncPageSize = 20;

  // 매일 새벽 3시에 실행 (초 분 시 일 월 요일)
  @Scheduled(fixedDelay = 5000)
  public void mngFileSyncJob00() {
    if (!isSchedulerEnabled) return;

    System.out.println("mngFileSyncJob00 === " + System.currentTimeMillis());
    mapSheetMngFileJobService.checkMapSheetFileProcess(0, mngSyncPageSize);
  }

  @Scheduled(fixedDelay = 5000)
  public void mngFileSyncJob01() {
    if (!isSchedulerEnabled) return;

    System.out.println("mngFileSyncJob01 === " + System.currentTimeMillis());
    mapSheetMngFileJobService.checkMapSheetFileProcess(1, mngSyncPageSize);
  }

  @Scheduled(fixedDelay = 5000)
  public void mngFileSyncJob02() {
    if (!isSchedulerEnabled) return;

    System.out.println("mngFileSyncJob00 === " + System.currentTimeMillis());
    mapSheetMngFileJobService.checkMapSheetFileProcess(2, mngSyncPageSize);
  }

  @Scheduled(fixedDelay = 5000)
  public void mngFileSyncJob03() {
    if (!isSchedulerEnabled) return;

    System.out.println("mngFileSyncJob03 === " + System.currentTimeMillis());
    mapSheetMngFileJobService.checkMapSheetFileProcess(3, mngSyncPageSize);
  }

  @Scheduled(fixedDelay = 5000)
  public void mngFileSyncJob04() {
    if (!isSchedulerEnabled) return;

    System.out.println("mngFileSyncJob04 === " + System.currentTimeMillis());
    mapSheetMngFileJobService.checkMapSheetFileProcess(4, mngSyncPageSize);
  }

  @Scheduled(fixedDelay = 5000)
  public void mngFileSyncJob05() {
    if (!isSchedulerEnabled) return;

    System.out.println("mngFileSyncJob05 === " + System.currentTimeMillis());
    mapSheetMngFileJobService.checkMapSheetFileProcess(5, mngSyncPageSize);
  }

  @Scheduled(fixedDelay = 5000)
  public void mngFileSyncJob06() {
    if (!isSchedulerEnabled) return;

    System.out.println("mngFileSyncJob06 === " + System.currentTimeMillis());
    mapSheetMngFileJobService.checkMapSheetFileProcess(6, mngSyncPageSize);
  }

  @Scheduled(fixedDelay = 5000)
  public void mngFileSyncJob07() {
    if (!isSchedulerEnabled) return;

    System.out.println("mngFileSyncJob07 === " + System.currentTimeMillis());
    mapSheetMngFileJobService.checkMapSheetFileProcess(7, mngSyncPageSize);
  }

  @Scheduled(fixedDelay = 5000)
  public void mngFileSyncJob08() {
    if (!isSchedulerEnabled) return;

    System.out.println("mngFileSyncJob08 === " + System.currentTimeMillis());
    mapSheetMngFileJobService.checkMapSheetFileProcess(8, mngSyncPageSize);
  }

  @Scheduled(fixedDelay = 5000)
  public void mngFileSyncJob09() {
    if (!isSchedulerEnabled) return;

    System.out.println("mngFileSyncJob09 === " + System.currentTimeMillis());
    mapSheetMngFileJobService.checkMapSheetFileProcess(9, mngSyncPageSize);
  }

  // 3. 외부에서 플래그를 변경할 수 있는 Setter 메서드
  public void setSchedulerEnabled(boolean enabled) {
    this.isSchedulerEnabled = enabled;
    System.out.println("스케줄러 상태 변경됨: " + (enabled ? "ON" : "OFF"));
  }

  public void setMngSyncPageSize(int pageSize) {
    this.mngSyncPageSize = pageSize;
    System.out.println("스케줄러 처리 개수 변경됨: " + pageSize);
  }
}
