
#nullable enable

namespace Google.Gemini
{
    /// <summary>
    /// Optional. Output only. The reason why the model stopped generating tokens. If empty, the model has not stopped generating tokens.<br/>
    /// Included only in responses
    /// </summary>
    public enum CandidateFinishReason
    {
        /// <summary>
        /// Token generation stopped because the content contains forbidden terms.
        /// </summary>
        Blocklist,
        /// <summary>
        /// Request was filtered by an escalation rule.
        /// </summary>
        Escalation,
        /// <summary>
        /// Default value. This value is unused.
        /// </summary>
        FinishReasonUnspecified,
        /// <summary>
        /// Image generation stopped because of other miscellaneous issue.
        /// </summary>
        ImageOther,
        /// <summary>
        /// Image generation stopped because generated images has other prohibited content.
        /// </summary>
        ImageProhibitedContent,
        /// <summary>
        /// Image generation stopped due to recitation.
        /// </summary>
        ImageRecitation,
        /// <summary>
        /// Token generation stopped because generated images contain safety violations.
        /// </summary>
        ImageSafety,
        /// <summary>
        /// The response candidate content was flagged for using an unsupported language.
        /// </summary>
        Language,
        /// <summary>
        /// The function call generated by the model is invalid.
        /// </summary>
        MalformedFunctionCall,
        /// <summary>
        /// Finished due to malformed response.
        /// </summary>
        MalformedResponse,
        /// <summary>
        /// The maximum number of tokens as specified in the request was reached.
        /// </summary>
        MaxTokens,
        /// <summary>
        /// Request has at least one thought signature missing.
        /// </summary>
        MissingThoughtSignature,
        /// <summary>
        /// The model was expected to generate an image, but none was generated.
        /// </summary>
        NoImage,
        /// <summary>
        /// Unknown reason.
        /// </summary>
        Other,
        /// <summary>
        /// Token generation stopped for potentially containing prohibited content.
        /// </summary>
        ProhibitedContent,
        /// <summary>
        /// The response candidate content was flagged for recitation reasons.
        /// </summary>
        Recitation,
        /// <summary>
        /// The response candidate content was flagged for safety reasons.
        /// </summary>
        Safety,
        /// <summary>
        /// Token generation stopped because the content potentially contains Sensitive Personally Identifiable Information (SPII).
        /// </summary>
        Spii,
        /// <summary>
        /// Natural stop point of the model or provided stop sequence.
        /// </summary>
        Stop,
        /// <summary>
        /// Model called too many tools consecutively, thus the system exited execution.
        /// </summary>
        TooManyToolCalls,
        /// <summary>
        /// Model generated a tool call but no tools were enabled in the request.
        /// </summary>
        UnexpectedToolCall,
    }

    /// <summary>
    /// Enum extensions to do fast conversions without the reflection.
    /// </summary>
    public static class CandidateFinishReasonExtensions
    {
        /// <summary>
        /// Converts an enum to a string.
        /// </summary>
        public static string ToValueString(this CandidateFinishReason value)
        {
            return value switch
            {
                CandidateFinishReason.Blocklist => "BLOCKLIST",
                CandidateFinishReason.Escalation => "ESCALATION",
                CandidateFinishReason.FinishReasonUnspecified => "FINISH_REASON_UNSPECIFIED",
                CandidateFinishReason.ImageOther => "IMAGE_OTHER",
                CandidateFinishReason.ImageProhibitedContent => "IMAGE_PROHIBITED_CONTENT",
                CandidateFinishReason.ImageRecitation => "IMAGE_RECITATION",
                CandidateFinishReason.ImageSafety => "IMAGE_SAFETY",
                CandidateFinishReason.Language => "LANGUAGE",
                CandidateFinishReason.MalformedFunctionCall => "MALFORMED_FUNCTION_CALL",
                CandidateFinishReason.MalformedResponse => "MALFORMED_RESPONSE",
                CandidateFinishReason.MaxTokens => "MAX_TOKENS",
                CandidateFinishReason.MissingThoughtSignature => "MISSING_THOUGHT_SIGNATURE",
                CandidateFinishReason.NoImage => "NO_IMAGE",
                CandidateFinishReason.Other => "OTHER",
                CandidateFinishReason.ProhibitedContent => "PROHIBITED_CONTENT",
                CandidateFinishReason.Recitation => "RECITATION",
                CandidateFinishReason.Safety => "SAFETY",
                CandidateFinishReason.Spii => "SPII",
                CandidateFinishReason.Stop => "STOP",
                CandidateFinishReason.TooManyToolCalls => "TOO_MANY_TOOL_CALLS",
                CandidateFinishReason.UnexpectedToolCall => "UNEXPECTED_TOOL_CALL",
                _ => throw new global::System.ArgumentOutOfRangeException(nameof(value), value, null),
            };
        }
        /// <summary>
        /// Converts an string to a enum.
        /// </summary>
        public static CandidateFinishReason? ToEnum(string value)
        {
            return value switch
            {
                "BLOCKLIST" => CandidateFinishReason.Blocklist,
                "ESCALATION" => CandidateFinishReason.Escalation,
                "FINISH_REASON_UNSPECIFIED" => CandidateFinishReason.FinishReasonUnspecified,
                "IMAGE_OTHER" => CandidateFinishReason.ImageOther,
                "IMAGE_PROHIBITED_CONTENT" => CandidateFinishReason.ImageProhibitedContent,
                "IMAGE_RECITATION" => CandidateFinishReason.ImageRecitation,
                "IMAGE_SAFETY" => CandidateFinishReason.ImageSafety,
                "LANGUAGE" => CandidateFinishReason.Language,
                "MALFORMED_FUNCTION_CALL" => CandidateFinishReason.MalformedFunctionCall,
                "MALFORMED_RESPONSE" => CandidateFinishReason.MalformedResponse,
                "MAX_TOKENS" => CandidateFinishReason.MaxTokens,
                "MISSING_THOUGHT_SIGNATURE" => CandidateFinishReason.MissingThoughtSignature,
                "NO_IMAGE" => CandidateFinishReason.NoImage,
                "OTHER" => CandidateFinishReason.Other,
                "PROHIBITED_CONTENT" => CandidateFinishReason.ProhibitedContent,
                "RECITATION" => CandidateFinishReason.Recitation,
                "SAFETY" => CandidateFinishReason.Safety,
                "SPII" => CandidateFinishReason.Spii,
                "STOP" => CandidateFinishReason.Stop,
                "TOO_MANY_TOOL_CALLS" => CandidateFinishReason.TooManyToolCalls,
                "UNEXPECTED_TOOL_CALL" => CandidateFinishReason.UnexpectedToolCall,
                _ => null,
            };
        }
    }
}