/*************************************************************************************
 * Copyright (C) 2012-2018 E.R.P. Consultores y Asociados, C.A.                      *
 * Contributor(s): Yamel Senih ysenih@erpya.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.grpc.util";
option java_outer_classname = "ADempiereAccess";
option objc_class_prefix = "HLW";

package access;

// The greeting service definition.
service Security {
  // Request login from user
  rpc RunLogin(LoginRequest) returns (Session) {}
  // Request a Role from uuid
  rpc RunLogout(LogoutRequest) returns (Session) {}
  // Request user roles from Session
  rpc GetUserInfo(UserInfoRequest) returns (UserInfo) {}
  // Request Menu from Parent UUID
  rpc GetMenu(MenuRequest) returns (Menu) {}
  // Request change role
  rpc RunChangeRole(ChangeRoleRequest) returns (Session) {}
  // Request session
  rpc GetSession(SessionRequest) returns (Session) {}
  // List Roles
  rpc ListRoles(ListRolesRequest) returns (ListRolesResponse) {}
}

// Translations Request
message ListRolesRequest {
	string session_uuid = 1;
	string language = 2;
	string client_version = 3;
	int32 page_size = 4;
	string page_token = 5;
}

//	Roles List
message ListRolesResponse {
	int64 record_count = 1;
	repeated Role roles = 2;
	string next_page_token = 3;
}

// Request a Login Session
message LoginRequest {
	string user_name = 1;
	string user_pass = 2;
	string role_uuid = 3;
	string organization_uuid = 4;
	string warehouse_uuid = 5;
	string client_version = 6;
	string language = 7;
	string token = 8;
}

// Request a Logout
message LogoutRequest {
	string session_uuid = 1;
	string language = 2;
	string client_version = 3;
}

// Request a Session
message SessionRequest {
	string session_uuid = 1;
	string language = 2;
	string client_version = 3;
}

// Request a Change Role
message ChangeRoleRequest {
	string session_uuid = 1;
	string role_uuid = 2;
	string organization_uuid = 3;
	string warehouse_uuid = 4;
	string language = 5;
	string client_version = 6;
}

// Request User Info
message UserInfoRequest {
	string session_uuid = 1;
	string language = 2;
	string client_version = 3;
}

// Request Menu
message MenuRequest {
	string session_uuid = 1;
	string language = 2;
	string client_version = 3;
}

// User information
message UserInfo {
	int32 id = 1;
	string uuid = 2;
	string name = 3;
	string description = 4;
	string comments = 5;
	string image = 6;
	int64 connection_timeout = 7;
}


// Session
message Session {
	int32 id = 1;
	string uuid = 2;
	string name = 3;
	UserInfo user_info = 4;
	Role role = 5;
	bool processed = 6;
	string language = 7;
	int32 country_id = 8;
	string country_code = 9;
	string country_name = 10;
	string display_sequence = 11;
	string currency_name = 12;
	string currency_iso_code = 13;
	string currency_symbol = 14;
	int32 standard_precision = 15;
	int32 costing_precision = 16;
	map<string, ContextValue> default_context = 17;
}

// Define value for object
message ContextValue {
	int32 int_value = 1;
	int64 long_value = 2;
	double double_value = 3;
	bool boolean_value = 4;
	string string_value = 5;
	enum ValueType {
		NULL = 0;
		INTEGER = 1;
		LONG = 2;
		DOUBLE = 3;
		BOOLEAN = 4;
		STRING = 5;
		DATE = 6;
	}
	ValueType value_type = 6;
}

// Role Definition
message Role {
	int32 id = 1;
	string uuid = 2;
	string name = 3;
	string description = 4;
	int32 client_id = 5;
	string client_name = 6;
	bool is_can_report = 7;
	bool is_can_export = 8;
	bool is_personal_lock = 9;
	bool is_personal_access = 10;
	bool is_allow_info_account = 11;
	bool is_allow_info_business_partner = 12;
	bool is_allow_info_in_out = 13;
	bool is_allow_info_order = 14;
	bool is_allow_info_product = 15;
	bool is_allow_info_schedule = 16;
	bool is_allow_info_mrp = 17;
	bool is_allow_html_view = 18;
	bool is_allow_info_asset = 19;
	bool is_allow_info_cash_journal = 20;
	bool is_allow_info_invoice = 21;
	bool is_allow_info_payment = 22;
	bool is_allow_info_resource = 23;
	bool is_allow_info_crp = 24;
	bool is_allow_xls_view = 25;
}

// Menu
message Menu {
	int32 id = 1;
	string uuid = 2;
	string parent_uuid = 4;
	string name = 5;
	string description = 6;
	string sequence = 7;
	bool is_read_only = 8;
	bool is_summary = 9;
	bool is_s_o_trx = 10;
	string action = 11;
	// Supported References
	string reference_uuid = 12;
	repeated Menu childs = 13;
	bool is_active = 14;
}
