// 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.ces.v1;

import "google/api/field_behavior.proto";
import "google/api/resource.proto";

option go_package = "cloud.google.com/go/ces/apiv1/cespb;cespb";
option java_multiple_files = true;
option java_outer_classname = "AgentTransfersProto";
option java_package = "com.google.cloud.ces.v1";

// Expression condition based on session state.
message ExpressionCondition {
  // Required. The string representation of cloud.api.Expression condition.
  string expression = 1 [(google.api.field_behavior) = REQUIRED];
}

// Python code block to evaluate the condition.
message PythonCodeCondition {
  // Required. The python code to execute.
  string python_code = 1 [(google.api.field_behavior) = REQUIRED];
}

// Rule for transferring to a specific agent.
message TransferRule {
  // Deterministic transfer rule. When the condition evaluates to true, the
  // transfer occurs.
  message DeterministicTransfer {
    // The condition to evaluate.
    oneof condition_type {
      // Optional. A rule that evaluates a session state condition.
      // If the condition evaluates to true, the transfer occurs.
      ExpressionCondition expression_condition = 1
          [(google.api.field_behavior) = OPTIONAL];

      // Optional. A rule that uses Python code block to evaluate the
      // conditions. If the condition evaluates to true, the transfer occurs.
      PythonCodeCondition python_code_condition = 2
          [(google.api.field_behavior) = OPTIONAL];
    }
  }

  // A rule that prevents the planner from transferring to the target agent.
  message DisablePlannerTransfer {
    // Required. If the condition evaluates to true, planner will not be allowed
    // to transfer to the target agent.
    ExpressionCondition expression_condition = 1
        [(google.api.field_behavior) = REQUIRED];
  }

  // The direction of the transfer.
  enum Direction {
    // Unspecified direction.
    DIRECTION_UNSPECIFIED = 0;

    // Transfer from the parent agent to the child agent.
    PARENT_TO_CHILD = 1;

    // Transfer from the child agent to the parent agent.
    CHILD_TO_PARENT = 2;
  }

  // The rule type.
  oneof rule_type {
    // Optional. A rule that immediately transfers to the target agent when the
    // condition is met.
    DeterministicTransfer deterministic_transfer = 3
        [(google.api.field_behavior) = OPTIONAL];

    // Optional. Rule that prevents the planner from transferring to the target
    // agent.
    DisablePlannerTransfer disable_planner_transfer = 4
        [(google.api.field_behavior) = OPTIONAL];
  }

  // Required. The resource name of the child agent the rule applies to.
  // Format:
  // `projects/{project}/locations/{location}/apps/{app}/agents/{agent}`
  string child_agent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = { type: "ces.googleapis.com/Agent" }
  ];

  // Required. The direction of the transfer.
  Direction direction = 2 [(google.api.field_behavior) = REQUIRED];
}
