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() {
        // #275 — 데몬 운영 설정은 admin 전용 (이전: 공개 노출 — 정보 누출 위험)
        AuthUtil.requireAdmin();
        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);
    }
}
