package com.honey.honey.controller;

import com.honey.honey.dto.NotifyBroadcastRequest;
import com.honey.honey.service.NotificationBroadcastService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * Admin API to trigger or stop notification broadcast (ADMIN only).
 */
@Slf4j
@RestController
@RequestMapping("/api/admin/notifications")
@RequiredArgsConstructor
@PreAuthorize("hasRole('ADMIN')")
public class AdminNotificationController {

    private final NotificationBroadcastService notificationBroadcastService;

    @PostMapping("/send")
    public ResponseEntity<Void> send(@RequestBody(required = false) NotifyBroadcastRequest body) {
        NotifyBroadcastRequest req = body != null ? body : new NotifyBroadcastRequest();
        notificationBroadcastService.runBroadcast(
                req.getMessage(),
                req.getImageUrl(),
                req.getVideoUrl(),
                req.getUserIdFrom(),
                req.getUserIdTo(),
                req.getButtonText(),
                req.getIgnoreBlocked());
        return ResponseEntity.accepted().build();
    }

    @PostMapping("/stop")
    public ResponseEntity<Void> stop() {
        notificationBroadcastService.requestStop();
        return ResponseEntity.ok().build();
    }
}
