package me.koba1.led.controller;

import me.koba1.led.Main;
import org.springframework.http.MediaType;
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;

import java.util.List;

@RestController
@RequestMapping("/api/console")
public class ConsoleController {
    public record MessageResponse(String message) {}

    @GetMapping
    public List<String> getMessages() {
        return Main.getLogger().getMessages();
    }

    @PostMapping("/clear")
    public ResponseEntity<MessageResponse> clear() {
        Main.getLogger().clear();
        return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(new MessageResponse("Console cleared"));
    }
}
