package NDMInterface;

message TUser {
    enum TRole {
        NOT_ALLOWED = 1;
        WATCHER = 2;
        ADMINISTRATOR = 3;
        SUPER_USER = 4;
    }
    message TRoleInProject {
        required string Project = 1;
        required TRole Role = 2;
    }
    required string Login = 1;
    required TRole DefaultRole = 2;
    repeated TRoleInProject RoleInProject = 3; 
}

message TProject {
    message TComponent {
        required string ServiceName = 1;
        required string ServiceType = 2;
        optional bool Main = 3;
    }

    message TProjectUser {
        required string Login = 1;
        required TUser.TRole Role = 2;
    }

    message TDocumentExample {
        required string Format = 1;
        required string Example = 2;
    }

    message TRequestExample {
        message TParam {
            message TValue {
                required string Data = 1;
                optional string Description = 2;
            }
            required string Name = 1;
            optional string Description = 2;
            repeated TValue Values = 3;
            optional bool Optional = 4[default=false];
        }
        repeated TParam Params = 1;
    }

    required string Name = 1;
    optional string Caption = 2 [default = ""];
    optional uint64 EstimatedDocumentsCount = 3 [default = 0];
    optional uint64 EstimatedIndexRpsMax = 4 [default = 0];
    optional uint64 EstimatedIndexRpsAverage = 5 [default = 0];
    optional uint64 EstimatedSearchRpsMax = 6 [default = 0];
    optional uint64 EstimatedSearchRpsAverage = 7 [default = 0];
    optional uint64 NeededResponseTimeout = 8 [default = 0];
    optional float NeededNotTimeoutResquestPart = 9 [default = 0.99];
    optional bool SuggestNeeded = 10 [default = false];
    repeated TComponent Components = 11;
    repeated TProjectUser Users = 12;
    repeated TDocumentExample DocumentExamples = 13;
    repeated TRequestExample RequestExamples = 14;
}

message TProjectConfig {
    message TFiles {
        message TFile {
            required string Path = 1;
            required int32 Version = 2;
        }
        repeated TFile File = 1;
    }

    message TComponent {
        required TProject.TComponent Component = 1;
        required TFiles Files = 2;
    }

    required uint64 Timestamp = 1;
    repeated TComponent Components = 2;
    required TFiles CommonFiles = 3;
    required string Name = 4;
}

message TRelevConfig {
    message TFactor {
        enum TStorageType {
            FLOAT = 1;
            INTEGER = 2;
        }

        message TZoneFactorAlgorithm {
            enum TValue {
                BM25F = 1;
                CZL = 2;
                CZ  = 3;
                ZL  = 4;
                CM  = 5;
                IF  = 6;
            }
            optional TValue Value = 1;
            repeated string AllowedValues = 2;
        }

        message TZoneFactorFormClass {
            enum TValue {
                Sy = 1;
                Lm = 2;
                St = 3;
            }
            optional TValue Value = 1;
            repeated string AllowedValues = 2;
        }

        required string Name = 1;
        required uint32 Index = 2;
        optional TStorageType StorageType = 4 [default = FLOAT];
        optional uint32 Width = 5 [default = 32];
        optional float DefaultValue = 6 [default = 0];
        optional bool HasDefaultValue = 7 [default = false];
        optional TZoneFactorAlgorithm ZoneFactorAlgorithm = 8;
        optional TZoneFactorFormClass ZoneFactorFormClass = 9;
    }

    message TFactorSet {
        enum TType {
            STATIC = 1;
            DYNAMIC = 2;
            ZONE = 3;
            USER = 4;
        }
        required TType Type = 1;
        required string Name = 2;
        repeated TFactor Factors = 3;
        repeated string FormClassAllowedValues = 4;
        repeated string AlgorithmAllowedValues = 5;
    }

    message TFactorId {
        required uint32 Id = 1;
    }

    message TMatrixNet {
        repeated TFactorId UsedFactors = 1;
        required TProjectConfig.TFiles.TFile File = 2;
        optional string Name = 3;
    }

    message TPolynom {
        message TMonom {
            required float Weight = 1;
            repeated TFactorId Factor = 2;
        }
        repeated TMonom Monoms = 1;
        repeated TFactorId UsedFactors = 2;
        optional string Encoded = 3;
    }

    message TFormula {
        required string Id = 1;
        optional TPolynom Polynom = 2;
        optional TMatrixNet MatrixNet = 3;
    }

    repeated TFactorSet FactorSets = 1;
    repeated TFormula Formulas = 7;
}

message TConfigField {
    enum TType {
        STRING = 1;
        INTEGER = 2;
        BOOLEAN = 3;
        FLOAT = 4;
        ENUM = 10;
        HTML_PARSER_ATTRIBUTE = 5;
        HTML_PARSER_ZONE = 6;
        XML_PARSER_ATTRIBUTE = 7;
        XML_PARSER_ZONE = 8;
        QUERY_LANGUAGE = 9;
    }

    enum TDefaultState {
        NO_DEFAULT = 1;
        HAS_DEFAULT = 2;
        IS_DEFAULT = 3;
    }

    required TType Type = 1;
    required TDefaultState DefaultState = 2;
    required string Name = 3;
    optional string Value = 4;
    optional string DefaultValue = 5;
    optional double MinValue = 6;
    optional double MaxValue = 7;
    required bool ShowInSimpleForm = 8 [default = true];
    required string DisplayName = 9;
    repeated string AllowedValues = 10;
}

message TConfigTab {
    enum TType {
        RTYSERVER_MAIN = 1;
        RTYSERVER_QUERY_LANGUAGE = 2;
        RTYSERVER_HTML_PARSER = 3;
        RTYSERVER_XML_PARSER = 4;
        RTYSERVER_RELEV = 5;

        SUGGEST = 11;
    }
    required TType Type = 1;
    required string TabName = 2;
    optional bool Required = 3;
    required bool Enabled = 4;
    required string FilePath = 5;
    repeated TConfigField Fields = 6;
    optional TRelevConfig RelevConfig = 7;
}

message TConfigSnapshot {
    repeated TConfigTab Tabs = 1;
}

message TCurrentConfigVersion {
    message TChangeProgress {
        optional uint32 From = 1;
        required uint32 To = 2;
        required uint64 Start = 3;
    }
    optional uint32 Version = 1;
    optional TChangeProgress ChangeProgress = 2;
}

message TServiceWizardCommonData {
    required string Id = 1;
    required string Title = 3;
    optional string Description = 4;
    optional string Condition = 5;
    optional string Hint = 6;
}

message TServiceWizardQuestion {
    enum TType {
        TEXT = 1;
        INTEGER = 2;
        FLOAT = 3;
        CHECK_BOX = 4;
        ENUM = 5;
        CHECK_LIST = 6;
        DATE = 7;
        LIST = 8;
        STRINGS = 9;
    }

    required TServiceWizardCommonData Common = 1;
    required TType Type = 2;
    repeated TServiceWizardCommonData AnswerOptions = 3;
    optional double MinValue = 4;
    optional double MaxValue = 5;
    optional string Value = 6;
    repeated TServiceWizardQuestion ListItemParts = 7;
}

message TServiceWizardPage {
    required TServiceWizardCommonData Common = 1;
    repeated TServiceWizardQuestion Questions = 2;
}

message TServiceWizard {
    repeated TServiceWizardPage Pages = 1;
}

message TServiceWizardReply {
    message TError {
        enum TLevel {
            INFO = 1;
            WARNING = 2;
            ERROR = 3;
        }
        message TLink {
            required string QuestionId = 1;
            required string PageId = 2;
            required string Text = 3;
        }
        required TLevel Level = 1;
        required string Message = 2;
        repeated TLink Links = 3;
        
    }

    message TFile {
        required string Name = 1;
        required string Content = 2;
    }

    repeated TError Errors = 1;
    repeated TFile Files = 2;
    optional TProject Project = 3;
    required bool Ok = 4[default=false];
}