syntax = "proto3";

package spamcheck;

import "google/protobuf/timestamp.proto";

message Generic {
    User user = 1;
    string text = 2;
    string type = 3;
    google.protobuf.Timestamp created_at = 4;
    google.protobuf.Timestamp updated_at = 5;
    Action action = 6;
    bool user_in_project = 7; // Whether or not the user is an authorized project member
    Project project = 8;
}

message Issue {
    User user = 1;
    string title = 2;
    string description = 3;
    google.protobuf.Timestamp created_at = 4;
    google.protobuf.Timestamp updated_at = 5;
    Action action = 6;
    bool user_in_project = 7; // Whether or not the user is an authorized project member
    Project project = 8;
}

message Snippet {
    User user = 1;
    string title = 2;
    string description = 3;
    string visibility = 4;
    google.protobuf.Timestamp created_at = 5;
    google.protobuf.Timestamp updated_at = 6;
    Action action = 7;
    bool user_in_project = 9; // Whether or not the user is an authorized project member
    Project project = 10;
    repeated File files = 11;
}

message User {
    repeated Email emails = 1;
    string org = 2;
    string username = 3;
    google.protobuf.Timestamp created_at = 4;
    map<string, float> abuse_metadata = 5;
    int32 id = 6;

    message Email {
        string email = 1;
        bool verified = 2;
    }
}

message Project {
    int32 project_id = 1;
    string project_path = 2;
}

message File {
    string path = 1;
}

message SpamVerdict {
    enum Verdict {
        ALLOW = 0;
        CONDITIONAL_ALLOW = 1;
        DISALLOW = 2;
        BLOCK = 3;
        NOOP = 4;
    }
    Verdict verdict = 1;
    string  error = 2 [deprecated=true];
    map<string, string> extra_attributes = 3 [deprecated=true];

    // introduced in v1.5.0
    float score = 4;
    string reason = 5;

    // introduced in v1.6.0
    bool evaluated = 6;
}

enum Action {
    CREATE = 0;
    UPDATE = 1;
}

service SpamcheckService {
    rpc CheckForSpamGeneric(Generic) returns (SpamVerdict) { }
    rpc CheckForSpamIssue(Issue) returns (SpamVerdict) { }
    rpc CheckForSpamSnippet(Snippet) returns (SpamVerdict) { }
}
