/************************************************************************************
 * Copyright (C) 2012-2023 E.R.P. Consultores y Asociados, C.A.                     *
 * Contributor(s): Edwin Betancourt EdwinBetanc0urt@outlook.com                     *
 * This program is free software: you can redistribute it and/or modify             *
 * it under the terms of the GNU General Public License as published by             *
 * the Free Software Foundation, either version 2 of the License, or                *
 * (at your option) any later version.                                              *
 * This program is distributed in the hope that it will be useful,                  *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                     *
 * GNU General Public License for more details.                                     *
 * You should have received a copy of the GNU General Public License                *
 * along with this program. If not, see <https://www.gnu.org/licenses/>.            *
 ************************************************************************************/
syntax = "proto3";

option java_multiple_files = true;
option java_package = "org.spin.backend.grpc.dashboarding";
option java_outer_classname = "ADempiereDashboarding";

import "proto/base_data_type.proto";
import "proto/dictionary.proto";

package dashboarding;

//	All related to Dashboarding
service Dashboarding {
	//	Request Dashboards Content Edit
	rpc ListDashboards(ListDashboardsRequest) returns (ListDashboardsResponse) {}
	//	Request Favorites
	rpc ListFavorites(ListFavoritesRequest) returns (ListFavoritesResponse) {}
	//	Request Document Statuses
	rpc ListPendingDocuments(ListPendingDocumentsRequest) returns (ListPendingDocumentsResponse) {}
	//	Get Metrics
	rpc GetMetrics(GetMetricsRequest) returns (Metrics) {}
	// NotificationWindowChart
	rpc ListNotifications(ListNotificationsRequest) returns (ListNotificationsResponse) {}
	// Custom Window Metrics
	rpc ExistsWindowDashboards(ExistsWindowDashboardsRequest) returns (ExistsWindowDashboardsResponse) {}
	rpc ListWindowDashboards(ListWindowDashboardsRequest) returns (ListWindowDashboardsResponse) {}
	rpc GetWindowMetrics(GetWindowMetricsRequest) returns (WindowMetrics) {}
}

// Dashboard
message Dashboard {
	string window_uuid = 1;
	string browser_uuid = 2;
	string name = 3;
	string description = 4;
	string html = 5;
	int32 column_no = 6;
	int32 line_no = 7;
	bool is_collapsible = 8;
	bool is_open_by_default = 9;
	bool is_event_required = 10;
	string file_name = 11;
	string dashboard_type = 12;
	string chart_type = 13;
	int32 id = 14;
	string uuid = 15;
}

// Dashboards Request
message ListDashboardsRequest {
	string role_uuid = 2;
	int32 role_id = 3;
	int32 page_size = 4;
	string page_token = 5;
}

//	Dashboards List
message ListDashboardsResponse {
	int64 record_count = 1;
	repeated Dashboard dashboards = 2;
	string next_page_token = 3;
}

// Favorites Items Request
message ListFavoritesRequest {
	string user_uuid = 2;
	int32 user_id = 3;
	int32 page_size = 4;
	string page_token = 5;
}

// Recent Item
message Favorite {
	string menu_uuid = 1;
	string menu_name = 2;
	string menu_description = 3;
	string reference_uuid = 4;
	string action = 5;
}

//	Recent Items List
message ListFavoritesResponse {
	int64 record_count = 1;
	repeated Favorite favorites = 2;
	string next_page_token = 3;
}

// Document Statuses Request
message ListPendingDocumentsRequest {
	string user_uuid = 2;
	int32 user_id = 3;
	string role_uuid = 4;
	int32 role_id = 5;
	int32 page_size = 6;
	string page_token = 7;
}

//	Recent Items List
message ListPendingDocumentsResponse {
	int64 record_count = 1;
	repeated PendingDocument pending_documents = 2;
	string next_page_token = 3;
}

// Recent Item
message PendingDocument {
	string window_uuid = 1;
	string form_uuid = 2;
	string document_name = 3;
	string document_description = 4;
	int32 sequence = 5;
	int64 record_count = 6;
	// Query
	data.Criteria criteria = 7;
}

// Metrics Request
message GetMetricsRequest {
	string uuid = 2;
	int32 id = 3;
}

// Metrics
message Metrics {
	string uuid = 1;
	int32 id = 2;
	string name = 3;
	string description = 4;
	string x_axis_label = 5;
	string y_axis_label = 6;
	data.Decimal measure_target = 7;
	repeated ColorSchema color_schemas = 8;
	repeated ChartSerie series = 9;
}

//	Serie
message ChartSerie {
	string name = 1;
	repeated ChartData data_set = 2;
}

//	Data of Chart
message ChartData {
	string name = 1;
	data.Decimal value = 2;
}

//	Color Schema
message ColorSchema {
	string name = 1;
	string color = 2;
	data.Decimal percent = 3;
}

enum Action {
	WINDOW = 0;
	PROCESS = 1;
	REPORT = 2;
	BROWSER = 3;
	FORM = 4;
	WORKFLOW = 5;
}

message Notification {
	string name = 1;
	string description = 2;
	int32 quantity = 3;
	Action action = 4;
	string action_uuid = 5;
}

message ListNotificationsRequest {
	int32 page_size = 2;
	string page_token = 3;
	string search_value = 4;
}

message ListNotificationsResponse {
	int64 record_count = 1;
	repeated Notification notifications = 2;
	string next_page_token = 3;
}



// Window Chart
message ExistsWindowDashboardsRequest {
	int32 window_id = 1;
	string window_uuid = 2;
	int32 tab_id = 3;
	string tab_uuid = 4;
}

message ExistsWindowDashboardsResponse {
	int32 record_count = 1;
}

message WindowDashboardParameter {
	int32 id = 1;
	string uuid = 2;
	string name = 3;
	string description = 4;
	string help = 5;
	int32 sequence = 6;
	string column_name = 7;
	string column_sql = 8;
	int32 element_id = 9;
	int32 field_id = 10;
	bool is_mandatory = 11;
	bool is_range = 12;
	string default_value = 13;
	int32 display_type = 14;
	string v_format = 15;
	string value_min = 16;
	string value_max = 17;
	string display_logic = 18;
	string read_only_logic = 19;
	// External Info
	dictionary.Reference reference = 20;
}

message WindowDashboard {
	int32 id = 1;
	string uuid = 2;
	string name = 3;
	string description = 4;
	int32 sequence = 5;
	bool is_collapsible = 6;
	bool is_open_by_default = 7;
	string dashboard_type = 8;
	string chart_type = 9;
	repeated string context_column_names = 10;
	string transformation_script = 11;
	repeated WindowDashboardParameter parameters = 12;
}

message ListWindowDashboardsRequest {
	int32 page_size = 1;
	string page_token = 2;
	string search_value = 3;
	int32 window_id = 4;
	string window_uuid = 5;
	int32 tab_id = 6;
	string tab_uuid = 7;
}

message ListWindowDashboardsResponse {
	int64 record_count = 1;
	repeated WindowDashboard records = 2;
	string next_page_token = 3;
}

// Window Metrics
message WindowMetrics {
	int32 id = 1;
	string uuid = 2;
	string name = 3;
	string description = 4;
	string x_axis_label = 5;
	string y_axis_label = 6;
	data.Decimal measure_target = 7;
	repeated ColorSchema color_schemas = 8;
	repeated ChartSerie series = 9;
}

message Filter {
	string column_name = 1;
	data.Value value = 2;
	data.Value value_to = 3;
	repeated data.Value values = 4;
}

message GetWindowMetricsRequest {
	string uuid = 1;
	int32 id = 2;
	string table_name = 3;
	int32 record_id = 4;
	string record_uuid = 5;
	repeated data.KeyValue context_attributes = 6;
	repeated Filter filters = 7;
}
