package pl.polskalokalnie.moderation;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

/**
 * Lekki endpoint dla frontendu: pozwala sprawdzic dowolne pole tekstowe przez ten sam globalny
 * filtr tresci co reszta backendu (np. czaty renderowane po stronie klienta). Zwraca 204, gdy
 * tekst jest czysty, albo 400 z komunikatem, gdy zawiera niedozwolone slownictwo.
 */
@RestController
@RequestMapping("/api/moderation")
public class ModerationController {

    private final TextModerationService textModerationService;

    public ModerationController(TextModerationService textModerationService) {
        this.textModerationService = textModerationService;
    }

    @PostMapping("/check")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void check(@RequestBody ModerationCheckRequest request) {
        textModerationService.validateOrThrow(request.text());
    }
}
