package com.zsElectric.boot.business.controller;

import com.zsElectric.boot.charging.quartz.ChargingJob;
import com.zsElectric.boot.common.annotation.Log;
import com.zsElectric.boot.common.enums.LogModuleEnum;
import com.zsElectric.boot.core.web.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 定时任务手动触发控制器
 *
 * @author system
 * @since 2025-12-12
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Tag(name = "定时任务管理")
@RequestMapping("/dev/v1/job")
public class JobManualTriggerController {

    private final ChargingJob chargingJob;

    /**
     * 手动触发价格策略同步任务
     */
    @Operation(summary = "手动触发价格策略同步任务")
    @PostMapping("/sync-price-policy")
    @Log(value = "手动触发价格策略同步任务", module = LogModuleEnum.PARKING_CALL, params = true, result = true)
    public Result<String> syncPricePolicy() {
        log.info("收到手动触发价格策略同步请求");
        
        try {
            // 调用定时任务方法
            chargingJob.syncEquipmentPricePolicy();
            return Result.success("价格策略同步任务已完成，请查看日志了解详细信息");
        } catch (Exception e) {
            log.error("手动触发价格策略同步任务失败", e);
            return Result.failed("价格策略同步任务执行失败: " + e.getMessage());
        }
    }

    /**
     * 手动触发充电站信息同步任务
     */
    @Operation(summary = "手动触发充电站信息同步任务")
    @PostMapping("/sync-stations-info")
    @Log(value = "手动触发充电站信息同步任务", module = LogModuleEnum.PARKING_CALL, params = true, result = true)
    public Result<String> syncStationsInfo() {
        log.info("收到手动触发充电站信息同步请求");
        
        try {
            // 调用定时任务方法
            chargingJob.syncStationsInfo();
            return Result.success("充电站信息同步任务已完成，请查看日志了解详细信息");
        } catch (Exception e) {
            log.error("手动触发充电站信息同步任务失败", e);
            return Result.failed("充电站信息同步任务执行失败: " + e.getMessage());
        }
    }
}
