package com.ffii.fpsms.modules.common.scheduler.web

import com.ffii.fpsms.modules.common.SettingNames
import com.ffii.fpsms.modules.common.scheduler.service.SchedulerService
import com.ffii.fpsms.modules.settings.service.SettingsService
import jakarta.validation.Valid
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/scheduler")
class SchedulerController(
    val schedulerService: SchedulerService,
    val settingsService: SettingsService
) {
    @GetMapping("/testDetailedProd")
    fun testDetailedProd(): Any {
        schedulerService.getDetailedProdSchedule()
        return 200
    }

    // Cron Settings
    @GetMapping("/updateSetting/poCron")
    fun schedulePo(@RequestParam @Valid newCron: String) {
        settingsService.update(SettingNames.SCHEDULE_M18_PO, newCron);
        schedulerService.scheduleM18PoTask()
    }
}