# frozen_string_literal: true

module OpenAI
  module Models
    module Chat
      class ChatCompletionMessage < OpenAI::Internal::Type::BaseModel
        # @!attribute content
        #   The contents of the message.
        #
        #   @return [String, nil]
        required :content, String, nil?: true

        response_only do
          # @!attribute parsed
          #   The parsed contents of the message, if JSON schema is specified.
          #
          #   @return [Object, nil]
          optional :parsed, OpenAI::StructuredOutput::ParsedJson
        end

        # @!attribute refusal
        #   The refusal message generated by the model.
        #
        #   @return [String, nil]
        required :refusal, String, nil?: true

        # @!attribute role
        #   The role of the author of this message.
        #
        #   @return [Symbol, :assistant]
        required :role, const: :assistant

        # @!attribute annotations
        #   Annotations for the message, when applicable, as when using the
        #   [web search tool](https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat).
        #
        #   @return [Array<OpenAI::Models::Chat::ChatCompletionMessage::Annotation>, nil]
        optional :annotations,
                 -> { OpenAI::Internal::Type::ArrayOf[OpenAI::Chat::ChatCompletionMessage::Annotation] }

        # @!attribute audio
        #   If the audio output modality is requested, this object contains data about the
        #   audio response from the model.
        #   [Learn more](https://platform.openai.com/docs/guides/audio).
        #
        #   @return [OpenAI::Models::Chat::ChatCompletionAudio, nil]
        optional :audio, -> { OpenAI::Chat::ChatCompletionAudio }, nil?: true

        # @!attribute function_call
        #   @deprecated
        #
        #   Deprecated and replaced by `tool_calls`. The name and arguments of a function
        #   that should be called, as generated by the model.
        #
        #   @return [OpenAI::Models::Chat::ChatCompletionMessage::FunctionCall, nil]
        optional :function_call, -> { OpenAI::Chat::ChatCompletionMessage::FunctionCall }

        # @!attribute tool_calls
        #   The tool calls generated by the model, such as function calls.
        #
        #   @return [Array<OpenAI::Models::Chat::ChatCompletionMessageFunctionToolCall, OpenAI::Models::Chat::ChatCompletionMessageCustomToolCall>, nil]
        optional :tool_calls,
                 -> { OpenAI::Internal::Type::ArrayOf[union: OpenAI::Chat::ChatCompletionMessageToolCall] }

        # @!method initialize(content:, refusal:, annotations: nil, audio: nil, function_call: nil, tool_calls: nil, role: :assistant)
        #   Some parameter documentations has been truncated, see
        #   {OpenAI::Models::Chat::ChatCompletionMessage} for more details.
        #
        #   A chat completion message generated by the model.
        #
        #   @param content [String, nil] The contents of the message.
        #
        #   @param refusal [String, nil] The refusal message generated by the model.
        #
        #   @param annotations [Array<OpenAI::Models::Chat::ChatCompletionMessage::Annotation>] Annotations for the message, when applicable, as when using the
        #
        #   @param audio [OpenAI::Models::Chat::ChatCompletionAudio, nil] If the audio output modality is requested, this object contains data
        #
        #   @param function_call [OpenAI::Models::Chat::ChatCompletionMessage::FunctionCall] Deprecated and replaced by `tool_calls`. The name and arguments of a function th
        #
        #   @param tool_calls [Array<OpenAI::Models::Chat::ChatCompletionMessageFunctionToolCall, OpenAI::Models::Chat::ChatCompletionMessageCustomToolCall>] The tool calls generated by the model, such as function calls.
        #
        #   @param role [Symbol, :assistant] The role of the author of this message.

        class Annotation < OpenAI::Internal::Type::BaseModel
          # @!attribute type
          #   The type of the URL citation. Always `url_citation`.
          #
          #   @return [Symbol, :url_citation]
          required :type, const: :url_citation

          # @!attribute url_citation
          #   A URL citation when using web search.
          #
          #   @return [OpenAI::Models::Chat::ChatCompletionMessage::Annotation::URLCitation]
          required :url_citation, -> { OpenAI::Chat::ChatCompletionMessage::Annotation::URLCitation }

          # @!method initialize(url_citation:, type: :url_citation)
          #   A URL citation when using web search.
          #
          #   @param url_citation [OpenAI::Models::Chat::ChatCompletionMessage::Annotation::URLCitation] A URL citation when using web search.
          #
          #   @param type [Symbol, :url_citation] The type of the URL citation. Always `url_citation`.

          # @see OpenAI::Models::Chat::ChatCompletionMessage::Annotation#url_citation
          class URLCitation < OpenAI::Internal::Type::BaseModel
            # @!attribute end_index
            #   The index of the last character of the URL citation in the message.
            #
            #   @return [Integer]
            required :end_index, Integer

            # @!attribute start_index
            #   The index of the first character of the URL citation in the message.
            #
            #   @return [Integer]
            required :start_index, Integer

            # @!attribute title
            #   The title of the web resource.
            #
            #   @return [String]
            required :title, String

            # @!attribute url
            #   The URL of the web resource.
            #
            #   @return [String]
            required :url, String

            # @!method initialize(end_index:, start_index:, title:, url:)
            #   A URL citation when using web search.
            #
            #   @param end_index [Integer] The index of the last character of the URL citation in the message.
            #
            #   @param start_index [Integer] The index of the first character of the URL citation in the message.
            #
            #   @param title [String] The title of the web resource.
            #
            #   @param url [String] The URL of the web resource.
          end
        end

        # @deprecated
        #
        # @see OpenAI::Models::Chat::ChatCompletionMessage#function_call
        class FunctionCall < OpenAI::Internal::Type::BaseModel
          # @!attribute arguments
          #   The arguments to call the function with, as generated by the model in JSON
          #   format. Note that the model does not always generate valid JSON, and may
          #   hallucinate parameters not defined by your function schema. Validate the
          #   arguments in your code before calling your function.
          #
          #   @return [String]
          required :arguments, String

          # @!attribute name
          #   The name of the function to call.
          #
          #   @return [String]
          required :name, String

          # @!method initialize(arguments:, name:)
          #   Some parameter documentations has been truncated, see
          #   {OpenAI::Models::Chat::ChatCompletionMessage::FunctionCall} for more details.
          #
          #   Deprecated and replaced by `tool_calls`. The name and arguments of a function
          #   that should be called, as generated by the model.
          #
          #   @param arguments [String] The arguments to call the function with, as generated by the model in JSON forma
          #
          #   @param name [String] The name of the function to call.
        end
      end
    end

    ChatCompletionMessage = Chat::ChatCompletionMessage
  end
end
