syntax = "proto3";

package berty.directory.v1;

import "protocoltypes.proto";
import "tagger/tagger.proto";

option go_package = "berty.tech/berty/go/pkg/directorytypes";

// DirectoryService
service DirectoryService {
  rpc Register(Register.Request) returns (Register.Reply);

  rpc Query(Query.Request) returns (stream Query.Reply);

  rpc Unregister(Unregister.Request) returns (Unregister.Reply);
}

message Register {
  message Request {
    bytes verified_credential = 1;
    int64 expiration_date = 2;
    int64 locked_until_date = 3;
    string account_uri = 4;
    bool overwrite_existing_record = 5;
  }
  message Reply {
    string directory_record_token = 1;
    string directory_identifier = 2;
    int64 expiration_date = 3;
    string unregister_token = 4;
  }
}

message Query {
  message Request {
    repeated string directory_identifiers = 1;
  }
  message Reply {
    string directory_identifier = 1;
    int64 expires_at = 2;
    string account_uri = 3;
    bytes verified_credential = 4;
  }
}

message Unregister {
  message Request {
    string directory_identifier = 1;
    string directory_record_token = 2;
    string unregister_token = 3; // when not known (ie. device lost) the user can either wait for the record to expire or register again (if the record is still present but unlocked) and then unregister
  }
  message Reply {}
}

message Record {
  string directory_identifier = 1 [(tagger.tags) = "gorm:\"index;primaryKey;autoIncrement:false\""];
  string directory_record_token = 2;
  int64 expires_at = 3;
  int64 locked_until = 4;
  string unregister_token = 5;
  string account_uri = 6;
  bytes verified_credential = 7;
}
