package com.cloudhandson.ddsbackoffice.service;

import static org.assertj.core.api.Assertions.assertThat;
import com.cloudhandson.ddsbackoffice.domain.DdsMcpAuthenticatedUser;
import com.cloudhandson.ddsbackoffice.domain.DdsMcpEndUserPrincipal;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;

class DdsMcpSseServiceTest {

  private final ObjectMapper objectMapper = new ObjectMapper();

  @Test
  void exposesNoBearerTokenToolParameter() throws Exception {
    // tools/list never calls the query service; null collaborators keep this
    // schema-contract test independent from bytecode-agent based mocks.
    var service = new DdsMcpSseService(objectMapper,
        new DdsMcpVectorSearchService(null, null, null, null));
    var user = new DdsMcpAuthenticatedUser(101L, "agent", new DdsMcpEndUserPrincipal(
        101L, "DDS_U_101", "DDS_U_101_ROLE", "DDS_OCI_IAM_CLIENT_SECRET_DERIVED_V1"));
    var request = objectMapper.readTree("""
        {"jsonrpc":"2.0","id":1,"method":"tools/list"}
        """);

    var response = service.handle(user, request);
    var schema = response.path("result").path("tools").get(0).path("inputSchema");

    assertThat(response.path("error").isMissingNode()).isTrue();
    assertThat(schema.path("required").get(0).asText()).isEqualTo("query");
    assertThat(schema.path("properties").has("bearerToken")).isFalse();
    assertThat(schema.path("properties").path("embeddingMode").path("enum").toString())
        .isEqualTo("[\"DEMO\",\"AI\"]");
  }
}
