package dev.sonpx.loyalty.agent.controller;

import dev.sonpx.loyalty.agent.domain.ChatRequest;
import dev.sonpx.loyalty.agent.service.LoyaltyAgentService;
import java.security.Principal;
import lombok.RequiredArgsConstructor;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin(origins = "*")
@RequiredArgsConstructor
public class AgentController {

    private final LoyaltyAgentService agentService;

    @MessageMapping("/chat")
    public void chat(@Payload ChatRequest request, Principal principal) {
        agentService.chat(request, principal.getName());
    }

}
