/**
 * Messages used in rpc communication between providers.
 * @author Michal Stanisz
 * @copyright (C) 2022 ACK CYFRONET AGH
 * @copyright This software is released under the MIT license cited in
 * 'LICENSE.txt'
 */

syntax = "proto2";
package one.clproto;

import "common_messages.proto";
import "time_series_messages.proto";

// Generic provider RPC call
message ProviderRpcCall {
    required bytes file_guid = 1;
    oneof operation {
        ProviderCurrentDirSizeStatsBrowseRequest provider_current_dir_size_stats_browse_request  = 2;
        ProviderHistoricalDirSizeStatsBrowseRequest provider_historical_dir_size_stats_browse_request  = 3;
        ProviderRegDistributionGetRequest provider_reg_distribution_get_request = 4;
        ProviderRegStorageLocationsGetRequest provider_reg_storage_locations_get_request = 5;
        ProviderQosStatusGetRequest provider_qos_status_get_request = 6;
        ProviderDirDistributionGetRequest provider_dir_distribution_get_request = 7;
    }
}

message ProviderCurrentDirSizeStatsBrowseRequest {
    repeated bytes stat_names = 1;
}

message ProviderHistoricalDirSizeStatsBrowseRequest {
    oneof request {
        TimeSeriesLayoutGetRequest time_series_layout_get_request = 1;
        TimeSeriesSliceGetRequest time_series_slice_get_request = 2;
    }
}

message ProviderRegDistributionGetRequest {
}

message ProviderRegStorageLocationsGetRequest {
}

message ProviderQosStatusGetRequest {
    required string qos_entry_id = 1;
}

message ProviderDirDistributionGetRequest {
    required ProviderCurrentDirSizeStatsBrowseRequest stats_request = 1;
}



// Generic provider RPC response
message ProviderRpcResponse {
    enum Status {
        ok      = 1;
        error   = 2;
    }
    required Status status = 1;
    oneof result {
        bytes error_json = 2;
        ProviderCurrentDirSizeStatsBrowseResult provider_current_dir_size_stats_browse_result = 3;
        TimeSeriesLayoutGetResult time_series_layout_get_result = 4;
        TimeSeriesSliceGetResult time_series_slice_get_result = 5;
        ProviderRegDistributionGetResult provider_reg_distribution_get_result = 6;
        ProviderRegStorageLocationsResult provider_reg_storage_locations_result = 7;
        ProviderQosStatusGetResult provider_qos_status_get_result = 8;
        ProviderDirDistributionGetResult provider_dir_distribution_get_result = 9;
    }
}

message ProviderCurrentDirSizeStatsBrowseResult {
    required bytes stats_as_json = 1;
    optional bytes error_json = 2;
}

message StorageRegDistributionGetResult {
    required bytes storage_id = 1;
    repeated FileBlock blocks = 2;
    optional bytes location = 3;
}

message ProviderRegDistributionGetResult {
    required uint64 logical_size = 1;
    repeated StorageRegDistributionGetResult distribution_per_storage = 2;
}

message StorageLocation {
    required bytes storage_id = 1;
    optional bytes location = 2;
    optional bytes error_json = 3;
}

message ProviderRegStorageLocationsResult {
    repeated StorageLocation locations = 1;
}

message ProviderQosStatusGetResult {
    enum Status {
        pending = 1;
        fulfilled = 2;
        impossible = 3;
    };
    required Status status = 1;
}

message ProviderDirDistributionGetResult {
    required ProviderCurrentDirSizeStatsBrowseResult dir_size_stats = 1;
    repeated StorageLocation storage_location = 2;
}
