// Copyright 2026 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.

syntax = "proto3";

package google.cloud.bigquery.v2;

option go_package = "cloud.google.com/go/bigquery/v2/apiv2/bigquerypb;bigquerypb";
option java_multiple_files = true;
option java_outer_classname = "GenAiStatsProto";
option java_package = "com.google.cloud.bigquery.v2";

// Provides error statistics for a GenAi function call.
message GenAiFunctionErrorStats {
  // A list of unique errors at function level (up to 5, truncated to 100
  // chars).
  repeated string errors = 3;

  // Number of failed rows processed by the function
  int64 num_failed_rows = 5;
}

// Provides cost optimization statistics for a GenAi function call.
message GenAiFunctionCostOptimizationStats {
  // Number of rows inferred via cost optimized workflow.
  optional int64 num_cost_optimized_rows = 1;

  // System generated message to provide insights into cost optimization state.
  optional string message = 2;
}

// Provides cache statistics for a GenAi function call.
message GenAiFunctionCacheStats {
  // Number of rows served from cache.
  optional int64 num_cache_hit_rows = 1;
}

// Provides statistics for each Ai function call within a query.
message GenAiFunctionStats {
  // Name of the function.
  optional string function_name = 1;

  // User input prompt of the function (truncated to 20 chars).
  optional string prompt = 2;

  // Number of rows processed by this GenAi function.
  // This includes all cost_optimized, llm_inferred and failed_rows.
  optional int64 num_processed_rows = 3;

  // Error stats for the function.
  optional GenAiFunctionErrorStats error_stats = 4;

  // Cost optimization stats if applied on the rows processed by the function.
  optional GenAiFunctionCostOptimizationStats cost_optimization_stats = 5;

  // Cache stats for the function.
  optional GenAiFunctionCacheStats cache_stats = 6;
}

// Provides error statistics for the query job across all AI function calls.
message GenAiErrorStats {
  // A list of unique errors at query level (up to 5, truncated to 100 chars)
  repeated string errors = 1;
}

// GenAi stats for the query job.
message GenAiStats {
  // Job level error stats across all GenAi functions
  optional GenAiErrorStats error_stats = 4;

  // Function level stats for GenAi Functions.
  // See https://docs.cloud.google.com/bigquery/docs/generative-ai-overview
  repeated GenAiFunctionStats function_stats = 5;
}
