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

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/chronicle/v1/dashboard_chart.proto";
import "google/cloud/chronicle/v1/dashboard_query.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";
import "google/rpc/status.proto";

option csharp_namespace = "Google.Cloud.Chronicle.V1";
option go_package = "cloud.google.com/go/chronicle/apiv1/chroniclepb;chroniclepb";
option java_multiple_files = true;
option java_outer_classname = "NativeDashboardProto";
option java_package = "com.google.cloud.chronicle.v1";
option php_namespace = "Google\\Cloud\\Chronicle\\V1";
option ruby_package = "Google::Cloud::Chronicle::V1";

// A service providing functionality for managing native dashboards.
service NativeDashboardService {
  option (google.api.default_host) = "chronicle.googleapis.com";
  option (google.api.oauth_scopes) =
      "https://www.googleapis.com/auth/chronicle,"
      "https://www.googleapis.com/auth/chronicle.readonly,"
      "https://www.googleapis.com/auth/cloud-platform";

  // Create a dashboard.
  rpc CreateNativeDashboard(CreateNativeDashboardRequest)
      returns (NativeDashboard) {
    option (google.api.http) = {
      post: "/v1/{parent=projects/*/locations/*/instances/*}/nativeDashboards"
      body: "native_dashboard"
    };
    option (google.api.method_signature) = "parent,native_dashboard";
  }

  // Get a dashboard.
  rpc GetNativeDashboard(GetNativeDashboardRequest) returns (NativeDashboard) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/locations/*/instances/*/nativeDashboards/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // List all dashboards.
  rpc ListNativeDashboards(ListNativeDashboardsRequest)
      returns (ListNativeDashboardsResponse) {
    option (google.api.http) = {
      get: "/v1/{parent=projects/*/locations/*/instances/*}/nativeDashboards"
    };
    option (google.api.method_signature) = "parent";
  }

  // Update a dashboard.
  rpc UpdateNativeDashboard(UpdateNativeDashboardRequest)
      returns (NativeDashboard) {
    option (google.api.http) = {
      patch: "/v1/{native_dashboard.name=projects/*/locations/*/instances/*/nativeDashboards/*}"
      body: "native_dashboard"
    };
    option (google.api.method_signature) = "native_dashboard,update_mask";
  }

  // Duplicate a dashboard.
  rpc DuplicateNativeDashboard(DuplicateNativeDashboardRequest)
      returns (NativeDashboard) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/instances/*/nativeDashboards/*}:duplicate"
      body: "*"
    };
    option (google.api.method_signature) = "name, native_dashboard";
  }

  // Delete a dashboard.
  rpc DeleteNativeDashboard(DeleteNativeDashboardRequest)
      returns (google.protobuf.Empty) {
    option (google.api.http) = {
      delete: "/v1/{name=projects/*/locations/*/instances/*/nativeDashboards/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Add chart in a dashboard.
  rpc AddChart(AddChartRequest) returns (AddChartResponse) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/instances/*/nativeDashboards/*}:addChart"
      body: "*"
    };
    option (google.api.method_signature) =
        "name, dashboard_query, dashboard_chart";
  }

  // Remove chart from a dashboard.
  rpc RemoveChart(RemoveChartRequest) returns (NativeDashboard) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/instances/*/nativeDashboards/*}:removeChart"
      body: "*"
    };
    option (google.api.method_signature) = "name";
  }

  // Edit chart in a dashboard.
  rpc EditChart(EditChartRequest) returns (EditChartResponse) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/instances/*/nativeDashboards/*}:editChart"
      body: "*"
    };
    option (google.api.method_signature) =
        "name, dashboard_query, dashboard_chart, edit_mask";
  }

  // Duplicate chart in a dashboard.
  rpc DuplicateChart(DuplicateChartRequest) returns (DuplicateChartResponse) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/instances/*/nativeDashboards/*}:duplicateChart"
      body: "*"
    };
    option (google.api.method_signature) = "name";
  }

  // Exports the dashboards.
  rpc ExportNativeDashboards(ExportNativeDashboardsRequest)
      returns (ExportNativeDashboardsResponse) {
    option (google.api.http) = {
      post: "/v1/{parent=projects/*/locations/*/instances/*}/nativeDashboards:export"
      body: "*"
    };
    option (google.api.method_signature) = "parent, names";
  }

  // Imports the dashboards.
  rpc ImportNativeDashboards(ImportNativeDashboardsRequest)
      returns (ImportNativeDashboardsResponse) {
    option (google.api.http) = {
      post: "/v1/{parent=projects/*/locations/*/instances/*}/nativeDashboards:import"
      body: "*"
    };
    option (google.api.method_signature) = "parent,source";
  }
}

// Type of the dashboard.
enum DashboardType {
  // Default unspecified.
  DASHBOARD_TYPE_UNSPECIFIED = 0;

  // Out of the box curated dashboards provided by Chronicle.
  CURATED = 1;

  // Private dashboards created by users/customers.
  PRIVATE = 2;

  // Public dashboards created by users/customers.
  PUBLIC = 3;

  // Custom dashboards
  CUSTOM = 4;

  // Marketplace dashboards
  MARKETPLACE = 5;
}

// AccessType of the dashboard.
enum DashboardAccess {
  // Default unspecified.
  DASHBOARD_ACCESS_UNSPECIFIED = 0;

  // Private dashboards created by users/customers.
  DASHBOARD_PRIVATE = 1;

  // Public dashboards created by users/customers.
  DASHBOARD_PUBLIC = 2;
}

// NativeDashboardView indicates the scope of fields to populate when returning
// the dashboard resource.
enum NativeDashboardView {
  // Defaults to basic.
  NATIVE_DASHBOARD_VIEW_UNSPECIFIED = 0;

  // Include basic metadata about the dashboard without full definition.
  NATIVE_DASHBOARD_VIEW_BASIC = 1;

  // Include everything.
  NATIVE_DASHBOARD_VIEW_FULL = 2;
}

// Request message to export list of dashboard.
message ExportNativeDashboardsRequest {
  // Required. The parent resource that the dashboards to be exported belong to.
  // Format: projects/{project}/locations/{location}/instances/{instance}
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "chronicle.googleapis.com/NativeDashboard"
    }
  ];

  // Required. The resource names of the dashboards to export.
  repeated string names = 2 [(google.api.field_behavior) = REQUIRED];
}

// Response message for exporting a dashboard.
message ExportNativeDashboardsResponse {
  // Destination for the exported data.
  oneof destination {
    // The data for the exported dashboards included directly in the response.
    InlineDestination inline_destination = 1;
  }
}

// InlineDestination for exporting a dashboard.
message InlineDestination {
  // Dashboards with charts and queries.
  repeated NativeDashboardWithChartsAndQueries dashboards = 1;
}

// NativeDashboardWithChartsAndQueries for exporting a dashboard.
message NativeDashboardWithChartsAndQueries {
  // Optional. Native dashboard.
  NativeDashboard dashboard = 1 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Charts in the dashboard.
  repeated DashboardChart dashboard_charts = 2
      [(google.api.field_behavior) = OPTIONAL];

  // Optional. Queries in the dashboard.
  repeated DashboardQuery dashboard_queries = 3
      [(google.api.field_behavior) = OPTIONAL];
}

// Request message to import dashboards.
message ImportNativeDashboardsRequest {
  // Required. The parent resource where this dashboard will be created.
  // Format: projects/{project}/locations/{location}/instances/{instance}
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "chronicle.googleapis.com/NativeDashboard"
    }
  ];

  // Required. The data will imported from this proto.
  ImportNativeDashboardsInlineSource source = 2
      [(google.api.field_behavior) = REQUIRED];
}

// Inline source for importing dashboards.
message ImportNativeDashboardsInlineSource {
  // Required. Dashboards with charts and queries.
  repeated NativeDashboardWithChartsAndQueries dashboards = 1
      [(google.api.field_behavior) = REQUIRED];
}

// Response message for importing dashboards.
message ImportNativeDashboardsResponse {
  // Output only. Represents the status of an import operation for multiple
  // dashboards. Each dashboard's import status is tracked. A status of OK
  // indicates the dashboard was ready for import. Otherwise, an appropriate
  // error code and message are provided. Importantly, the import process is
  // all-or-nothing: if even one dashboard fails to import, the entire import
  // operation is aborted, and none of the dashboards are imported. The order of
  // the statuses will be the same as in the import request.
  repeated ImportExportStatus results = 1
      [(google.api.field_behavior) = OUTPUT_ONLY];
}

// ImportExportStatus is a wrapper for dashboard name and status.
message ImportExportStatus {
  // The resource name of the dashboard if it was supplied in the request.
  string dashboard = 1;

  // Output only. Status of the import/export operation.
  google.rpc.Status status = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// NativeDashboard resource.
message NativeDashboard {
  option (google.api.resource) = {
    type: "chronicle.googleapis.com/NativeDashboard"
    pattern: "projects/{project}/locations/{location}/instances/{instance}/nativeDashboards/{dashboard}"
    plural: "nativeDashboards"
    singular: "nativeDashboard"
  };

  // Output only. Name of the dashboard.
  string name = 1 [
    (google.api.field_behavior) = OUTPUT_ONLY,
    (google.api.resource_reference) = {
      type: "chronicle.googleapis.com/NativeDashboard"
    }
  ];

  // Required. Dashboard display name/title visible to users.
  string display_name = 2 [(google.api.field_behavior) = REQUIRED];

  // Optional. Description of the dashboard.
  string description = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Definition of the dashboard like metadata, visualization and
  // datasource configuration etc.
  DashboardDefinition definition = 4 [(google.api.field_behavior) = OPTIONAL];

  // Output only. Whether it's an out of the box or custom created dashboard.
  DashboardType type = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Creation time of dashboard.
  google.protobuf.Timestamp create_time = 6
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Time the dashboard was last edited.
  google.protobuf.Timestamp update_time = 7
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. User who created the dashboard.
  string create_user_id = 8 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. User who last edited the dashboard.
  string update_user_id = 9 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. User Preferences for a dashboard
  DashboardUserData dashboard_user_data = 10
      [(google.api.field_behavior) = OUTPUT_ONLY];

  // Optional. This checksum is computed by the server based on the value of
  // other fields, and may be sent on update and delete requests to ensure the
  // client has an up-to-date value before proceeding.
  string etag = 11 [(google.api.field_behavior) = OPTIONAL];

  // Output only. Access of the dashboard
  DashboardAccess access = 12 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Request message to create a dashboard.
message CreateNativeDashboardRequest {
  // Required. The parent resource where this dashboard will be created.
  // Format: projects/{project}/locations/{location}/instances/{instance}
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "chronicle.googleapis.com/NativeDashboard"
    }
  ];

  // Required. The dashboard to create.
  NativeDashboard native_dashboard = 2 [(google.api.field_behavior) = REQUIRED];
}

// Request message to get a dashboard.
message GetNativeDashboardRequest {
  // Required. The dashboard name to fetch.
  // Format:
  // projects/{project}/locations/{location}/instances/{instance}/nativeDashboards/{dashboard}
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "chronicle.googleapis.com/NativeDashboard"
    }
  ];

  // Optional. View indicates the scope of fields to populate when returning the
  // dashboard resource. If unspecified, defaults to the basic view.
  NativeDashboardView view = 2 [(google.api.field_behavior) = OPTIONAL];
}

// Request message to list dashboards.
message ListNativeDashboardsRequest {
  // Required. The parent owning this dashboard collection.
  // Format: projects/{project}/locations/{location}/instances/{instance}
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "chronicle.googleapis.com/NativeDashboard"
    }
  ];

  // Optional. The maximum number of dashboards to return. The service may
  // return fewer than this value.
  int32 page_size = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. A page token, received from a previous `ListDashboards` call.
  // Provide this to retrieve the subsequent page.
  //
  // When paginating, all other parameters provided to `ListDashboards` must
  // match the call that provided the page token.
  string page_token = 3 [(google.api.field_behavior) = OPTIONAL];

  // Optional. View indicates the scope of fields to populate when returning the
  // dashboard resource. If unspecified, defaults to the basic view.
  NativeDashboardView view = 4 [(google.api.field_behavior) = OPTIONAL];
}

// Response message for listing dashboards.
message ListNativeDashboardsResponse {
  // The dashboards from the specified chronicle instance.
  repeated NativeDashboard native_dashboards = 1;

  // A token, which can be sent as `page_token` to retrieve the next page.
  // If this field is omitted, there are no subsequent pages.
  string next_page_token = 2;
}

// Request message to update a dashboard.
message UpdateNativeDashboardRequest {
  // Required. The dashboard to update.
  //
  // The dashboard's `name` field is used to identify the dashboard to update.
  // Format:
  // projects/{project}/locations/{location}/instances/{instance}/nativeDashboards/{dashboard}
  NativeDashboard native_dashboard = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. LINT.IfChange(update_mask_values)
  // The list of fields to update.
  // Supported paths are -
  // display_name
  // description
  // definition.filters
  // definition.charts
  // type
  // access
  // dashboard_user_data.is_pinned
  google.protobuf.FieldMask update_mask = 2
      [(google.api.field_behavior) = REQUIRED];
}

// Request message to duplicate a dashboard.
message DuplicateNativeDashboardRequest {
  // Required. The dashboard name to duplicate.
  // Format:
  // projects/{project}/locations/{location}/instances/{instance}/nativeDashboards/{dashboard}
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "chronicle.googleapis.com/NativeDashboard"
    }
  ];

  // Required. Any fields that need modification can be passed through this like
  // name, description etc.
  NativeDashboard native_dashboard = 2 [(google.api.field_behavior) = REQUIRED];
}

// Request message to delete a dashboard.
message DeleteNativeDashboardRequest {
  // Required. The dashboard name to delete.
  // Format:
  // projects/{project}/locations/{location}/instances/{instance}/nativeDashboards/{dashboard}
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "chronicle.googleapis.com/NativeDashboard"
    }
  ];
}

// Request message to add chart in a dashboard.
message AddChartRequest {
  // Required. The dashboard name to add chart in.
  // Format:
  // projects/{project}/locations/{location}/instances/{instance}/nativeDashboards/{dashboard}
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "chronicle.googleapis.com/NativeDashboard"
    }
  ];

  // Optional. Query used to create the chart.
  DashboardQuery dashboard_query = 2 [(google.api.field_behavior) = OPTIONAL];

  // Required. Chart to be added to the dashboard.
  DashboardChart dashboard_chart = 3 [(google.api.field_behavior) = REQUIRED];

  // Required. ChartLayout for newly added chart.
  DashboardDefinition.ChartConfig.ChartLayout chart_layout = 4
      [(google.api.field_behavior) = REQUIRED];
}

// Response message for adding chart in a dashboard.
message AddChartResponse {
  // Dashboard with chart added in definition.
  NativeDashboard native_dashboard = 1;

  // Created chart resource.
  DashboardChart dashboard_chart = 2;
}

// Request message to edit chart in a dashboard.
message EditChartRequest {
  // Required. The dashboard name to edit chart in.
  // Format:
  // projects/{project}/locations/{location}/instances/{instance}/nativeDashboards/{dashboard}
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "chronicle.googleapis.com/NativeDashboard"
    }
  ];

  // Optional. Query for the edited chart.
  DashboardQuery dashboard_query = 2 [(google.api.field_behavior) = OPTIONAL];

  // Optional. Edited chart.
  DashboardChart dashboard_chart = 3 [(google.api.field_behavior) = OPTIONAL];

  // Required. The list of fields to edit for chart and query.
  // Supported paths in chart are -
  // dashboard_chart.display_name
  // dashboard_chart.description
  // dashboard_chart.chart_datasource.data_sources
  // dashboard_chart.visualization
  // dashboard_chart.visualization.button
  // dashboard_chart.visualization.markdown
  // dashboard_chart.drill_down_config
  // Supported paths in query are -
  // dashboard_query.query
  // dashboard_query.input
  google.protobuf.FieldMask edit_mask = 4
      [(google.api.field_behavior) = REQUIRED];

  // Optional. Language Features present in the query.
  repeated LanguageFeature language_features = 5
      [(google.api.field_behavior) = OPTIONAL];
}

// Response message for editing chart in a dashboard.
message EditChartResponse {
  // Edited dashboard.
  NativeDashboard native_dashboard = 1;

  // Edited chart resource.
  DashboardChart dashboard_chart = 2;
}

// Request message to remove chart from a dashboard.
message RemoveChartRequest {
  // Required. The dashboard name to remove chart from.
  // Format:
  // projects/{project}/locations/{location}/instances/{instance}/nativeDashboards/{dashboard}
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "chronicle.googleapis.com/NativeDashboard"
    }
  ];

  // Required. The dashboard chart name to remove.
  string dashboard_chart = 2 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "chronicle.googleapis.com/DashboardChart"
    }
  ];
}

// Request message to duplicate chart in a dashboard.
message DuplicateChartRequest {
  // Required. The dashboard name that involves chart duplication.
  // Format:
  // projects/{project}/locations/{location}/instances/{instance}/nativeDashboards/{dashboard}
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "chronicle.googleapis.com/NativeDashboard"
    }
  ];

  // Required. The dashboard chart name to duplicate.
  string dashboard_chart = 2 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "chronicle.googleapis.com/DashboardChart"
    }
  ];
}

// Response message for duplicating chart in a dashboard.
message DuplicateChartResponse {
  // Dashboard with chart added in definition.
  NativeDashboard native_dashboard = 1;

  // Duplicated chart resource.
  DashboardChart dashboard_chart = 2;
}

// User Data for Native Dashboard
message DashboardUserData {
  // time when this dashboard is last viewed
  google.protobuf.Timestamp last_viewed_time = 1;

  // is dashboard pinned by user
  bool is_pinned = 2;
}

// Definition of the dashboard including filters, layout, charts'
// configurations.
message DashboardDefinition {
  // Configuration of the chart including chart reference, layout and filters.
  message ChartConfig {
    // Layout of the chart.
    message ChartLayout {
      optional int32 start_x = 9;

      int32 span_x = 10;

      optional int32 start_y = 11;

      int32 span_y = 12;
    }

    string dashboard_chart = 1 [
      (google.api.field_behavior) = OUTPUT_ONLY,
      (google.api.resource_reference) = {
        type: "chronicle.googleapis.com/DashboardChart"
      }
    ];

    ChartLayout chart_layout = 2;

    // Dashboard filters applied to the chart.
    repeated string filters_ids = 4;
  }

  // Filters for the dashboard.
  repeated DashboardFilter filters = 1;

  // Fingerprint of the dashboard definition.
  string fingerprint = 2;

  // Charts in the dashboard.
  repeated ChartConfig charts = 4;
}
