package com.sino.mci.inbound.controller;

import com.sino.mci.inbound.dto.ReceiveMessageRequest;
import com.sino.mci.inbound.entity.FlowExecutionTrace;
import com.sino.mci.inbound.service.InboundMessageService;
import com.sino.mci.shared.web.ApiResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/inbound")
@RequiredArgsConstructor
public class InboundMessageController {

    private final InboundMessageService inboundMessageService;

    @PostMapping("/receive")
    public ApiResponse<?> receiveMessage(
            @RequestHeader("X-Tenant-Code") String tenantCode,
            @Valid @RequestBody ReceiveMessageRequest request) {
        return ApiResponse.ok(inboundMessageService.receiveMessage(tenantCode, request));
    }

    @GetMapping("/{eventId}/trace")
    public ApiResponse<List<FlowExecutionTrace>> listTraces(@PathVariable String eventId) {
        return ApiResponse.ok(inboundMessageService.listTraces(eventId));
    }
}
