package com.smartoffice.notification;

import com.smartoffice.auth.UserPrincipal;
import com.smartoffice.common.ApiResponse;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/notifications")
public class NotificationController {
    private final NotificationService notificationService;

    public NotificationController(NotificationService notificationService) {
        this.notificationService = notificationService;
    }

    @GetMapping
    public ApiResponse<List<NotificationDto>> list(@AuthenticationPrincipal UserPrincipal principal) {
        return ApiResponse.ok(notificationService.listFor(principal.getUsername()));
    }

    @PostMapping("/{id}/read")
    public ApiResponse<NotificationDto> markRead(@AuthenticationPrincipal UserPrincipal principal, @PathVariable Long id) {
        return ApiResponse.ok(notificationService.markRead(principal.getUsername(), id));
    }
}
