package dev.ksan.etfoglasiserver.controller;

import dev.ksan.etfoglasiserver.model.RegisterTokenRequest;
import dev.ksan.etfoglasiserver.service.DeviceTokenService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/device-tokens")
@RequiredArgsConstructor
public class DeviceTokenController {

    private final DeviceTokenService deviceTokenService;

    @PostMapping("/register")
    public ResponseEntity<Void> register(
            @RequestBody RegisterTokenRequest request,
            @AuthenticationPrincipal UserDetails principal) {

        deviceTokenService.registerToken(
                principal.getUsername(),
                request.getToken());

        return ResponseEntity.noContent().build();
    }
}