package com.tasteby.controller;

import com.tasteby.domain.DaemonConfig;
import com.tasteby.security.AuthUtil;
import com.tasteby.service.DaemonConfigService;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/daemon")
public class DaemonController {

    private final DaemonConfigService daemonConfigService;

    public DaemonController(DaemonConfigService daemonConfigService) {
        this.daemonConfigService = daemonConfigService;
    }

    @GetMapping("/config")
    public DaemonConfig getConfig() {
        DaemonConfig config = daemonConfigService.getConfig();
        return config != null ? config : DaemonConfig.builder().build();
    }

    @PutMapping("/config")
    public Map<String, Object> updateConfig(@RequestBody Map<String, Object> body) {
        AuthUtil.requireAdmin();
        daemonConfigService.updateConfig(body);
        return Map.of("ok", true);
    }
}
