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

import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/ces/v1beta/common.proto";
import "google/protobuf/timestamp.proto";

option go_package = "cloud.google.com/go/ces/apiv1beta/cespb;cespb";
option java_multiple_files = true;
option java_outer_classname = "ChannelProfileProto";
option java_package = "com.google.cloud.ces.v1beta";

// Experiment for the deployment.
message ExperimentConfig {
  // Version release for the experiment.
  message VersionRelease {
    // Traffic allocation for the version release.
    message TrafficAllocation {
      // Optional. Id of the traffic allocation.
      // Free format string, up to 128 characters.
      string id = 1 [(google.api.field_behavior) = OPTIONAL];

      // Optional. Traffic percentage of the traffic allocation.
      // Must be between 0 and 100.
      int32 traffic_percentage = 2 [(google.api.field_behavior) = OPTIONAL];

      // Optional. App version of the traffic allocation.
      // Format:
      // `projects/{project}/locations/{location}/apps/{app}/versions/{version}`
      string app_version = 3 [
        (google.api.field_behavior) = OPTIONAL,
        (google.api.resource_reference) = {
          type: "ces.googleapis.com/AppVersion"
        }
      ];
    }

    // Optional. State of the version release.
    State state = 1 [(google.api.field_behavior) = OPTIONAL];

    // Optional. Traffic allocations for the version release.
    repeated TrafficAllocation traffic_allocations = 2
        [(google.api.field_behavior) = OPTIONAL];
  }

  // State of the experiment.
  enum State {
    // Unspecified state.
    STATE_UNSPECIFIED = 0;

    // Deprecated: This state is no longer used.
    PENDING = 1;

    // Running state. Experiment is running and valid.
    RUNNING = 2;

    // Deprecated: This state is no longer used.
    DONE = 3;

    // Deprecated: This state is no longer used.
    EXPIRED = 4;
  }

  // Optional. Version release for the experiment.
  VersionRelease version_release = 1 [(google.api.field_behavior) = OPTIONAL];
}

// A deployment represents an immutable, queryable version of the app.
// It is used to deploy an app version with a specific channel profile.
message Deployment {
  option (google.api.resource) = {
    type: "ces.googleapis.com/Deployment"
    pattern: "projects/{project}/locations/{location}/apps/{app}/deployments/{deployment}"
    plural: "deployments"
    singular: "deployment"
  };

  // Identifier. The resource name of the deployment.
  // Format:
  // `projects/{project}/locations/{location}/apps/{app}/deployments/{deployment}`
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Required. Display name of the deployment.
  string display_name = 8 [(google.api.field_behavior) = REQUIRED];

  // Optional. The resource name of the app version to deploy.
  // Format:
  // `projects/{project}/locations/{location}/apps/{app}/versions/{version}`
  // Use `projects/{project}/locations/{location}/apps/{app}/versions/-` to use
  // the draft app.
  string app_version = 2 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.resource_reference) = { type: "ces.googleapis.com/AppVersion" }
  ];

  // Required. The channel profile used in the deployment.
  ChannelProfile channel_profile = 3 [(google.api.field_behavior) = REQUIRED];

  // Output only. Timestamp when this deployment was created.
  google.protobuf.Timestamp create_time = 4
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Timestamp when this deployment was last updated.
  google.protobuf.Timestamp update_time = 5
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Etag used to ensure the object hasn't changed during a
  // read-modify-write operation. If the etag is empty, the update will
  // overwrite any concurrent changes.
  string etag = 7 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. Experiment configuration for the deployment.
  ExperimentConfig experiment_config = 9
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Input only. Ephemeral WhatsApp credentials required when
  // configuring a WhatsApp channel profile.
  WhatsAppCredentials whatsapp_credentials = 10 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.field_behavior) = INPUT_ONLY
  ];

  // Optional. Input only. Ephemeral Instagram credentials required when
  // configuring a Instagram channel profile.
  InstagramCredentials instagram_credentials = 11 [
    (google.api.field_behavior) = OPTIONAL,
    (google.api.field_behavior) = INPUT_ONLY
  ];
}

// Ephemeral Meta credentials for WhatsApp native integration.
message WhatsAppCredentials {
  // Required. The Meta auth code provided by the embedded signup flow.
  string auth_code = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. The 6-digit PIN created by the user for two-step verification.
  string pin = 2 [(google.api.field_behavior) = REQUIRED];

  // Required. The phone number to register with WhatsApp.
  string phone_number = 3 [(google.api.field_behavior) = REQUIRED];

  // Required. The Business Account ID to use for the phone number.
  string business_account_id = 4 [(google.api.field_behavior) = REQUIRED];

  // Required. The WhatsApp Business Account ID.
  string waba_id = 5 [(google.api.field_behavior) = REQUIRED];

  // Required. The Conversation Profile ID to use for the deployment.
  string conversation_profile_id = 6 [(google.api.field_behavior) = REQUIRED];
}

// Ephemeral Meta credentials for Instagram native integration.
message InstagramCredentials {
  // Required. The Meta auth code provided by the embedded signup flow.
  string auth_code = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. The Conversation Profile ID to use for the deployment.
  string conversation_profile_id = 2 [(google.api.field_behavior) = REQUIRED];
}
