package com.controllers;



import com.Modules.etl.handler.ETLRetryHandler;
import com.common.schedule.ETLOrchestrator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/api/etl")
public class ETLController {

    @Autowired
    private ETLOrchestrator etlOrchestrator;
    /**
     * 手动触发ETL任务
     */
    @PostMapping("/trigger")
    public ResponseEntity<String> triggerETL() {
        log.info("接收到手动触发ETL任务请求");
        try {
            etlOrchestrator.triggerETLManually();
            return ResponseEntity.ok("ETL任务执行成功");
        } catch (Exception e) {
            log.error("ETL任务执行失败", e);
            return ResponseEntity.status(500)
                    .body("ETL任务执行失败: " + e.getMessage());
        }
    }

    @PostMapping("/trigger/time")
    public ResponseEntity<String> triggerETLbyTime(String startTime ,String endTime ) {
        log.info("接收到手动触发ETL任务请求, 开始时间：{},结束时间：{}",startTime,endTime );
        try {
            etlOrchestrator.triggerETLManuallyByTime(startTime,endTime);
            return ResponseEntity.ok("ETL任务执行成功");
        } catch (Exception e) {
            log.error("ETL任务执行失败", e);
            return ResponseEntity.status(500)
                    .body("ETL任务执行失败: " + e.getMessage());
        }
    }
    /**
     * 健康检查接口
     */
    @PostMapping("/health")
    public ResponseEntity<String> healthCheck() {
        return ResponseEntity.ok("ETL服务运行正常");
    }
}