// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Foundation

/// Incremental server update generated by the model in response to client
/// messages.
///
/// Content is generated as quickly as possible, and not in realtime. Clients
/// may choose to buffer and play it out in realtime.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, *)
@available(watchOS, unavailable)
struct BidiGenerateContentServerContent: Decodable, Sendable {
  /// The content that the model has generated as part of the current
  /// conversation with the user.
  let modelTurn: ModelContent?

  /// If true, indicates that the model is done generating. Generation will only
  /// start in response to additional client messages. Can be set alongside
  /// `content`, indicating that the `content` is the last in the turn.
  let turnComplete: Bool?

  /// If true, indicates that a client message has interrupted current model
  /// generation. If the client is playing out the content in realtime, this is a
  /// good signal to stop and empty the current queue. If the client is playing
  /// out the content in realtime, this is a good signal to stop and empty the
  /// current playback queue.
  let interrupted: Bool?

  /// If true, indicates that the model is done generating.
  ///
  /// When model is interrupted while generating there will be no
  /// 'generation_complete' message in interrupted turn, it will go through
  /// 'interrupted > turn_complete'.
  ///
  /// When model assumes realtime playback there will be delay between
  /// generation_complete and turn_complete that is caused by model waiting for
  /// playback to finish.
  let generationComplete: Bool?

  /// Metadata specifies sources used to ground generated content.
  let groundingMetadata: GroundingMetadata?

  let inputTranscription: BidiGenerateContentTranscription?

  let outputTranscription: BidiGenerateContentTranscription?
}
