syntax = "proto3";

package wix.api;

option java_package = "com.wix.api";

import "google/protobuf/struct.proto";
import "google/protobuf/wrappers.proto";

message Details {
    oneof kind {
        ApplicationError application_error = 1;
        ValidationError validation_error = 2;
        SystemError system_error = 4;
    }
    map<string, string> tracing = 3 [deprecated = true]; // deprecated in API's - to enable migration from rendering arbitrary tracing to rest response
}

message ApplicationError {
    // Error code.
    string code = 1;
    // Description of the error.
    string description = 2;
    // Data related to the error.
    google.protobuf.Struct data = 3;
}

message SystemError {
    // Error code.
    google.protobuf.StringValue errorCode = 1;
}

/**
example result:
{
  "fieldViolations": [
    {
      "field": "fieldA",
      "description": "invalid music note. supported notes: [do,re,mi,fa,sol,la,ti]",
      "violatedRule": "OTHER",
      "ruleName": "INVALID_NOTE",
      "data": {
        "value": "FI"
      }
    },
    {
      "field": "fieldB",
      "description": "field value out of range. supported range: [0-20]",
      "violatedRule": "MAX",
      "data": {
        "threshold": 20
      }
    },
    {
      "field": "fieldC",
      "description": "invalid phone number. provide a valid phone number of size: [7-12], supported characters: [0-9, +, -, (, )]",
      "violatedRule": "FORMAT",
      "data": {
        "type": "PHONE"
      }
    }
  ]
}
**/
message ValidationError {
    enum RuleType {
        VALIDATION = 0;
        OTHER = 1;
        MAX = 2;
        MIN = 3;
        MAX_LENGTH = 4;
        MIN_LENGTH = 5;
        MAX_SIZE = 6;
        MIN_SIZE = 7;
        FORMAT = 8;
        DECIMAL_LTE = 9;
        DECIMAL_GTE = 10;
        DECIMAL_LT = 11;
        DECIMAL_GT = 12;
        DECIMAL_MAX_SCALE = 13;
        INVALID_ENUM_VALUE = 14;
        REQUIRED_FIELD = 15;
        FIELD_NOT_ALLOWED = 16;
        ONE_OF_ALIGNMENT = 17;
        EXACT_LENGTH = 18;
        EXACT_SIZE = 19;
        REQUIRED_ONE_OF_FIELD = 20;
    }
    message FieldViolation {
        string field = 1;
        string description = 2;
        RuleType violated_rule = 3;
        google.protobuf.StringValue rule_name = 4; // applicable when violated_rule=OTHER
        google.protobuf.Struct data = 5;
    }
    repeated FieldViolation field_violations = 1;
}

// for all kinds of min/max violations - match to type provided in annotation
message LimitRuleInt32DataPayload {
    int32 threshold = 1;
}

// for all kinds of min/max violations - match to type provided in annotation
message LimitRuleDoubleDataPayload {
    double threshold = 1;
}

// for all kinds of min/max violations - match to type provided in annotation
message LimitRuleStringDataPayload {
    string threshold = 1;
}

// for format violations
message FormatRuleDataPayload {
    string type = 1;
}

// for enum violations
message EnumRuleDataPayload {
    repeated string supported = 1;
}

// for required one-of violations
message RequiredOneOfRuleDataPayload {
    repeated string supported = 1;
}