/**
 * Communication protocol between Event Managers.
 * @author Krzysztof Trzepla
 * @copyright (C) 2015 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 "fuse_messages.proto";

message Events {
    repeated Event events = 1;
}

message FlushEvents {
    required bytes  provider_id          = 1;
    required bytes  context              = 2;
    required sint64 subscription_id      = 3;
}

// Generic event message
message Event {
    oneof type { // list of all event types
        FileReadEvent            file_read             = 1;
        FileWrittenEvent         file_written          = 2;
        FileAttrChangedEvent     file_attr_changed     = 3;
        FileLocationChangedEvent file_location_changed = 4;
        FilePermChangedEvent     file_perm_changed     = 5;
        FileRemovedEvent         file_removed          = 6;
        FileRenamedEvent         file_renamed          = 7;
        QuotaExceededEvent       quota_exceeded        = 8;
    }
}

message FileReadEvent {
    required uint32    counter   = 1; // amount of aggregated events
    required bytes     file_uuid = 2; // UUID of file associated with an event
    required uint64    size      = 3; // amount of read bytes
    repeated FileBlock blocks    = 4; // list of read blocks
}

message FileWrittenEvent {
    required uint32    counter   = 1; // amount of aggregated events
    required bytes     file_uuid = 2; // UUID of file associated with an event
    optional uint64    file_size = 3; // size of file associated with an event
    required uint64    size      = 4; // amount of written bytes
    repeated FileBlock blocks    = 5; // list of written blocks
}

message FileAttrChangedEvent {
    required FileAttr file_attr = 1;
}

message FileLocationChangedEvent {
    required FileLocation file_location = 1;
    optional uint64 change_beg_offset = 2;
    optional uint64 change_end_offset = 3;
}

message FilePermChangedEvent {
    required bytes file_uuid = 1; // UUID of file associated with an event
}

message FileRemovedEvent {
    required bytes file_uuid = 1; // UUID of file associated with an event
}

message FileRenamedEvent {
    required FileRenamedEntry top_entry = 1;     // entry for renamed file
    repeated FileRenamedEntry child_entries = 2; // entries for children of
                                                 // renamed file
}

message QuotaExceededEvent {
    repeated bytes spaces = 1; // Blocked spaces
}

// Generic subscription message
message Subscription {
    required sint64 id = 1; // unique subscription ID
    oneof type { // list of all subscription types
        FileReadSubscription            file_read             = 2;
        FileWrittenSubscription         file_written          = 3;
        FileAttrChangedSubscription     file_attr_changed     = 4;
        FileLocationChangedSubscription file_location_changed = 5;
        FilePermChangedSubscription     file_perm_changed     = 6;
        FileRemovedSubscription         file_removed          = 7;
        FileRenamedSubscription         file_renamed          = 8;
        QuotaExceededSubscription       quota_exceeded        = 9;
    }
}

message FileReadSubscription {
    optional uint32 counter_threshold = 1; // maximal amount of aggregated
                                           // events before emission
    optional uint32 time_threshold    = 2; // maximal delay in milliseconds
                                           // between successive events emission
}

message FileWrittenSubscription {
    optional uint32 counter_threshold = 1; // maximal amount of aggregated
                                           // events before emission
    optional uint32 time_threshold    = 2; // maximal delay in milliseconds
                                           // between successive events emission
}

message FileAttrChangedSubscription {
    required bytes  file_uuid         = 1; // file UUID
    optional uint32 time_threshold    = 2; // maximal delay in milliseconds
                                           // between successive events emission
}

message FileLocationChangedSubscription {
    required bytes  file_uuid         = 1; // file UUID
    optional uint32 time_threshold    = 2; // maximal delay in milliseconds
                                           // between successive events emission
}


message FilePermChangedSubscription {
    required bytes  file_uuid         = 1; // file UUID
}

message FileRemovedSubscription {
    required bytes  file_uuid         = 1; // file UUID
}

message FileRenamedSubscription {
    required bytes  file_uuid         = 1; // file UUID
}

message QuotaExceededSubscription {
}

message SubscriptionCancellation {
    required sint64 id = 1; // ID of subscription to be cancelled
}
