// 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";
import "google/protobuf/timestamp.proto";

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

// Represents an Omnichannel resource.
message Omnichannel {
  option (google.api.resource) = {
    type: "ces.googleapis.com/Omnichannel"
    pattern: "projects/{project}/locations/{location}/omnichannels/{omnichannel}"
    plural: "omnichannels"
    singular: "omnichannel"
  };

  // Identifier. The unique identifier of the omnichannel resource.
  // Format:
  // `projects/{project}/locations/{location}/omnichannels/{omnichannel}`
  string name = 1 [(google.api.field_behavior) = IDENTIFIER];

  // Required. Display name of the omnichannel resource.
  string display_name = 2 [(google.api.field_behavior) = REQUIRED];

  // Optional. Human-readable description of the omnichannel resource.
  string description = 3 [(google.api.field_behavior) = OPTIONAL];

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

  // Output only. Timestamp when the omnichannel resource 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.
  string etag = 6 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. The integration config for the omnichannel resource.
  OmnichannelIntegrationConfig integration_config = 7
      [(google.api.field_behavior) = OPTIONAL];
}

// OmnichannelIntegrationConfig contains all App integration configs.
message OmnichannelIntegrationConfig {
  // ChannelConfig contains config for various of app integration.
  message ChannelConfig {
    // The config for the app.
    oneof channel_config {
      // WhatsApp config.
      WhatsappConfig whatsapp_config = 1;
    }
  }

  // How Omnichannel should receive/reply events from WhatsApp.
  message WhatsappConfig {
    // The Phone Number ID associated with the WhatsApp Business Account.
    string phone_number_id = 1;

    // The phone number used for sending/receiving messages.
    string phone_number = 2;

    // The customer's WhatsApp Business Account (WABA) ID.
    string whatsapp_business_account_id = 3;

    // The verify token configured in the Meta App Dashboard for webhook
    // verification.
    string webhook_verify_token = 4;

    // The access token for authenticating API calls to the WhatsApp Cloud API.
    // https://developers.facebook.com/docs/whatsapp/business-management-api/get-started/#business-integration-system-user-access-tokens
    string whatsapp_business_token = 5;

    // The Meta Business Portfolio (MBP) ID.
    // https://www.facebook.com/business/help/1710077379203657
    string meta_business_portfolio_id = 6;
  }

  // Configs of subscribers.
  message SubscriberConfig {
    // The config for the subscriber.
    oneof subscriber_config {
      // Ces app config.
      CesAppConfig ces_app_config = 1;
    }
  }

  // Configs for CES app.
  message CesAppConfig {
    // The unique identifier of the CES app.
    // Format: `projects/{project}/locations/{location}/apps/{app}`
    string app = 1
        [(google.api.resource_reference) = { type: "ces.googleapis.com/App" }];
  }

  // Routing config specify how/who to route app events to a subscriber.
  message RoutingConfig {
    // The key of the subscriber.
    string subscriber_key = 1;
  }

  // Optional. Various of configuration for handling App events.
  map<string, ChannelConfig> channel_configs = 1
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Various of subscribers configs.
  map<string, SubscriberConfig> subscriber_configs = 2
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. The key of routing_configs is a key of `app_configs`, value is a
  // `RoutingConfig`, which contains subscriber's key.
  map<string, RoutingConfig> routing_configs = 3
      [(google.api.field_behavior) = OPTIONAL];
}
