// Copyright 2010 Google Inc. All Rights Reserved.
//
// 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.

// Author: aoates@google.com (Andrew Oates)

// Protocol buffers generated by the pagespeed::ProtoFormatter formatter

syntax = "proto2";

option optimize_for = LITE_RUNTIME;
option java_package = "com.googlecode.page_speed";

package pagespeed;

// Typed format string arguments.
message FormatArgument {

  // NOTE: these must be kept in sync with kArgumentTypeToNameMap in
  // formatted_results_to_json_converter.cc.
  enum ArgumentType {
    URL = 1;
    STRING_LITERAL = 2;
    INT_LITERAL = 3;
    BYTES = 4;
    DURATION = 5;
    // Used for pre-formatted strings such as code blocks or stack traces.
    VERBATIM_STRING = 6;
    PERCENTAGE = 7;
  }

  required ArgumentType type = 1;
  optional string string_value = 2;
  optional int64 int_value = 3;
  // A localized string representing the value (e.g. in the 'fr' locale, 3900
  // bytes might be localized as '3,9 kB')
  required string localized_value = 4;
}

// Pair of a format string and its arguments.
message FormatString {
  // Format string (e.g. 'You saved $1 bytes over $2 URLs').
  required string format = 1;
  // Format arguments (one for each of the $<n> placeholders above).
  repeated FormatArgument args = 2;
}

// Formatted results for a single URL.
message FormattedUrlResult {
  // Description of the URL's results.
  required FormatString result = 1;

  // Optional additional details.
  repeated FormatString details = 2;

  // The id of the Result object associated with this URL, if any.
  optional int32 associated_result_id = 3;
}

message FormattedUrlBlockResults {
  // Header summarizing this URL block.
  optional FormatString header = 1;

  // URLs in the block.
  repeated FormattedUrlResult urls = 2;

  // The id of the Result object associated with this URL block, if any.
  optional int32 associated_result_id = 3;
}

// Formatted and structured results from one rule.
message FormattedRuleResults {
  // The rule that generated these results.
  required string rule_name = 1;

  // Formatted version of the rule name.
  required string localized_rule_name = 2;

  // Blocks of URLs (e.g. one for each redirect chain to be eliminated).
  repeated FormattedUrlBlockResults url_blocks = 3;

  // Score assigned by Page Speed for this rule.  It should be set in most
  // cases, but may be left out if the rule is unable to compute a score (e.g.
  // due to missing input information).
  optional int32 rule_score = 4;

  // The impact number assigned by Page Speed for this rule.  Like the score,
  // this may be left out if it cannot be calculated.
  optional double rule_impact = 5;

  // The experimental bit indicate if the rule is experimental. Experimental
  // rules are new rules that we are trying out, which do not impact the
  // overall score, and are expected to either graduate to non-experimental
  // rules or else be deleted.
  optional bool experimental = 6;
}

// Formatted and localized results proto, mirroring the hiercharchy of results
// in the pagespeed::Results proto.
message FormattedResults {
  // Locale for which these results are generated.
  required string locale = 1;

  // Formatted results for each rule.
  repeated FormattedRuleResults rule_results = 2;

  // Overall score assigned by Page Speed.
  optional int32 score = 3;
}
