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

syntax = "proto3";

package cel.policy;

option cc_enable_arenas = true;
option go_package = "cel.dev/policy";
option java_multiple_files = true;
option java_package = "dev.cel.policy";

message PolicySpec {
  message Import {
    string name = 1;
  }

  message Variable {
    string name = 1;

    string description = 2;

    string expression = 3;
  }

  message Rule {
    string id = 1;

    string description = 2;

    repeated Variable variables = 3;

    repeated Match match = 4;
  }

  message Match {
    // If unset, the default is "true".
    optional string condition = 1;

    oneof action {
      string output = 2;

      Rule rule = 3;
    }

    string explanation = 4;
  }

  string name = 1;

  repeated Import imports = 2;

  // If set, [PolicySpec][match] and [PolicySpec][rule] must be unset.
  repeated Variable variables = 3;
  // If set, [PolicySpec][match] and [PolicySpec][rule] must be unset.
  optional string output = 4;
  // If set, [PolicySpec][match] and [PolicySpec][rule] must be unset.
  optional string description = 5;
  // If set, [PolicySpec][match] and [PolicySpec][rule] must be unset.
  optional string explanation = 6;

  // If set, [PolicySpec][variables], [PolicySpec][output], [PolicySpec][description],
  // [PolicySpec][explanation], and [PolicySpec][rule] must be unset.
  repeated Match match = 7;

  // If set, [PolicySpec][variables], [PolicySpec][output], [PolicySpec][description],
  // [PolicySpec][explanation], and [PolicySpec][match] must be unset.
  Rule rule = 8;
}
