001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.bean.mcp.v20260728;
018
019import org.apache.juneau.commons.bean.*;
020
021/**
022 * CRTP base for every successful MCP {@code 2026-07-28} result, carrying the required {@code resultType}
023 * discriminator and optional {@link ResultMeta} under the reserved {@code _meta} wire key.
024 *
025 * <p>
026 * The {@code 2026-07-28} schema declares {@code resultType} as an open string union: {@code "complete"} and
027 * {@code "input_required"} ({@link InputRequiredResult}, MRTR / SEP-2322) are the values this bean model
028 * permits. Only {@code "complete"} is emitted by any dispatch path today; {@code "input_required"} becomes
029 * reachable once MRTR pause/resume dispatch wiring is in place. Parsing remains lossless regardless and
030 * accepts any string a peer might send. The field therefore defaults to {@code "complete"} rather than being
031 * validated against a closed enumeration.
032 *
033 * <p>
034 * {@link CacheableResult} extends this base so the five cacheable list/read results inherit {@code resultType}
035 * and {@code _meta} alongside their cache hints. Every other concrete result bean ({@link CallToolResult},
036 * {@link GetPromptResult}, {@link CompleteResult}, and {@link PingResult}) extends this base directly.
037 *
038 * <p>
039 * The CRTP type parameter lets each concrete subclass's fluent setters return its own concrete type for method
040 * chaining, without duplicating the {@code resultType} / {@code _meta} accessors in every subclass.
041 *
042 * @param <T> The concrete subclass, for fluent-setter self-typing.
043 */
044@SuppressWarnings({
045   "unchecked" // CRTP subclasses bind T to their own concrete type.
046})
047public abstract class Result<T extends Result<T>> {
048
049   private String resultType = "complete";
050   private ResultMeta meta;
051
052   /**
053    * Result-type discriminator.
054    *
055    * <p>
056    * Defaults to {@code "complete"}. The schema defines this as an open string union, so parsing accepts any
057    * string losslessly.
058    *
059    * @return The result type. Never <jk>null</jk> on a server-constructed instance.
060    */
061   public String getResultType() {
062      return resultType;
063   }
064
065   /**
066    * Sets the result-type discriminator.
067    *
068    * @param value The new value.  Can be <jk>null</jk> to unset the property.
069    * @return This object (for method chaining).
070    */
071   public T setResultType(String value) {
072      resultType = value;
073      return (T)this;
074   }
075
076   /**
077    * Result metadata: server identity plus any echoed trace context.
078    *
079    * @return The metadata, or {@code null} if not set.
080    */
081   @BeanProp("_meta")
082   public ResultMeta getMeta() {
083      return meta;
084   }
085
086   /**
087    * Sets the result metadata.
088    *
089    * @param value The new value.  Can be <jk>null</jk> to unset the property.
090    * @return This object (for method chaining).
091    */
092   @BeanProp("_meta")
093   public T setMeta(ResultMeta value) {
094      meta = value;
095      return (T)this;
096   }
097}