/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

syntax = "proto3";

import "google/protobuf/timestamp.proto";

option go_package = "github.com/featureform/metadata/proto";

package featureform.serving.metadata.proto;

service Metadata {
    rpc ListFeatures(Empty) returns (stream Feature);
    rpc CreateFeatureVariant(FeatureVariant) returns (Empty);
    rpc GetFeatures(stream Name) returns (stream Feature);
    rpc GetFeatureVariants(stream NameVariant) returns (stream FeatureVariant);
    rpc ListLabels(Empty) returns (stream Label);
    rpc CreateLabelVariant(LabelVariant) returns (Empty);
    rpc GetLabels(stream Name) returns (stream Label);
    rpc GetLabelVariants(stream NameVariant) returns (stream LabelVariant);
    rpc ListTrainingSets(Empty) returns (stream TrainingSet);
    rpc CreateTrainingSetVariant(TrainingSetVariant) returns (Empty);
    rpc GetTrainingSets(stream Name) returns (stream TrainingSet);
    rpc GetTrainingSetVariants(stream NameVariant) returns (stream TrainingSetVariant);
    rpc ListSources(Empty) returns (stream Source);
    rpc CreateSourceVariant(SourceVariant) returns (Empty);
    rpc GetSources(stream Name) returns (stream Source);
    rpc GetSourceVariants(stream NameVariant) returns (stream SourceVariant);
    rpc ListUsers(Empty) returns (stream User);
    rpc CreateUser(User) returns (Empty);
    rpc GetUsers(stream Name) returns (stream User);
    rpc ListProviders(Empty) returns (stream Provider);
    rpc CreateProvider(Provider) returns (Empty);
    rpc GetProviders(stream Name) returns (stream Provider);
    rpc ListEntities(Empty) returns (stream Entity);
    rpc CreateEntity(Entity) returns (Empty);
    rpc GetEntities(stream Name) returns (stream Entity);
    rpc ListModels(Empty) returns (stream Model);
    rpc CreateModel(Model) returns (Empty);
    rpc GetModels(stream Name) returns (stream Model);
    rpc SetResourceStatus(SetStatusRequest) returns (Empty);
    rpc RequestScheduleChange(ScheduleChangeRequest) returns (Empty);
}

service Api {
    rpc CreateUser(User) returns (Empty);
    rpc CreateProvider(Provider) returns (Empty);
    rpc CreateSourceVariant(SourceVariant) returns (Empty);
    rpc CreateEntity(Entity) returns (Empty);
    rpc CreateFeatureVariant(FeatureVariant) returns (Empty);
    rpc CreateLabelVariant(LabelVariant) returns (Empty);
    rpc CreateTrainingSetVariant(TrainingSetVariant) returns (Empty);
    rpc RequestScheduleChange(ScheduleChangeRequest) returns (Empty);
    rpc GetUsers(stream Name) returns (stream User);
    rpc GetFeatures(stream Name) returns (stream Feature);
    rpc GetFeatureVariants(stream NameVariant) returns (stream FeatureVariant);
    rpc GetLabels(stream Name) returns (stream Label);
    rpc GetLabelVariants(stream NameVariant) returns (stream LabelVariant);
    rpc GetTrainingSets(stream Name) returns (stream TrainingSet);
    rpc GetTrainingSetVariants(stream NameVariant) returns (stream TrainingSetVariant);
    rpc GetSources(stream Name) returns (stream Source);
    rpc GetSourceVariants(stream NameVariant) returns (stream SourceVariant);
    rpc GetProviders(stream Name) returns (stream Provider);
    rpc GetEntities(stream Name) returns (stream Entity);
    rpc GetModels(stream Name) returns (stream Model);
    rpc ListFeatures(Empty) returns (stream Feature);
    rpc ListLabels(Empty) returns (stream Label);
    rpc ListTrainingSets(Empty) returns (stream TrainingSet);
    rpc ListSources(Empty) returns (stream Source);
    rpc ListUsers(Empty) returns (stream User);
    rpc ListProviders(Empty) returns (stream Provider);
    rpc ListEntities(Empty) returns (stream Entity);
    rpc ListModels(Empty) returns (stream Model);
}

message Name {
    string name = 1;
}


message ResourceStatus {
    enum Status {
        NO_STATUS = 0;
        CREATED = 1;
        PENDING = 2;
        READY = 3;
        FAILED = 4;
      }
    Status status = 1;
    string error_message = 2;
}

enum ResourceType {
    FEATURE = 0;
    LABEL = 1;
    TRAINING_SET = 2;
    SOURCE = 3;
    FEATURE_VARIANT = 4;
    LABEL_VARIANT = 5;
    TRAINING_SET_VARIANT = 6;
    SOURCE_VARIANT = 7;
    PROVIDER = 8;
    ENTITY = 9;
    MODEL = 10;
    USER = 11;
}

message ResourceID {
    NameVariant resource = 1;
    ResourceType resource_type = 2;
}

message SetStatusRequest {
    ResourceID resource_id = 1;
    ResourceStatus status = 2;
}

message ScheduleChangeRequest {
    ResourceID resource_id = 1;
    string schedule = 2;
}

message NameVariant {
    string name = 1;
    string variant = 2;
}

message Empty {}

message Feature {
    string name = 1;
    ResourceStatus status = 2;
    string default_variant = 3;
    repeated string variants = 4;
}

message Columns {
    string entity = 1;
    string value = 2;
    string ts = 3;
}

message FeatureVariant {
    string name = 1;
    string variant = 2;
    NameVariant source = 3;
    string type = 4;
    string entity = 5;
    google.protobuf.Timestamp created = 6;
    string owner = 7;
    string description = 8;
    string provider = 9;
    ResourceStatus status = 10;
    repeated NameVariant trainingsets = 11;
    oneof location {
        Columns columns = 12;
    }
    google.protobuf.Timestamp last_updated = 13;
    string schedule = 14;
}

message Label {
    string name = 1;
    ResourceStatus status = 2;
    string default_variant = 3;
    repeated string variants = 4;
}

message LabelVariant {
    string name = 1;
    string variant = 2;
    string description = 3;
    string type = 4;
    NameVariant source = 5;
    string entity = 6;
    google.protobuf.Timestamp created = 7;
    string owner = 8;
    string provider = 9;
    ResourceStatus status = 10;
    repeated NameVariant trainingsets = 11;
    oneof location {
        Columns columns = 12;
    }
}

message Provider {
    string name = 1;
    string description = 2;
    string type = 3;
    string software = 4;
    string team = 5;
    bytes serialized_config = 6;
    ResourceStatus status = 7;
    repeated NameVariant sources = 8;
    repeated NameVariant features = 9;
    repeated NameVariant trainingsets = 10;
    repeated NameVariant labels = 11;
}

message TrainingSet {
    string name = 1;
    ResourceStatus status = 2;
    string default_variant = 3;
    repeated string variants = 4;
}

message TrainingSetVariant {
    string name = 1;
    string variant = 2;
    string description = 3;
    string owner = 4;
    google.protobuf.Timestamp created = 5;
    string provider = 6;
    ResourceStatus status = 7;
    repeated NameVariant features = 8;
    NameVariant label = 9;
    google.protobuf.Timestamp last_updated = 13;
    string schedule = 14;
}

message Entity {
    string name = 1;
    string description = 2;
    ResourceStatus status = 3;
    repeated NameVariant features = 4;
    repeated NameVariant labels = 5;
    repeated NameVariant trainingsets = 6;
}

message Model {
    string name = 1;
    string description = 2;
    ResourceStatus status = 3;
    repeated NameVariant features = 4;
    repeated NameVariant labels = 5;
    repeated NameVariant trainingsets = 6;
}

message User {
    string name = 1;
    ResourceStatus status = 2;
    repeated NameVariant features = 3;
    repeated NameVariant labels = 4;
    repeated NameVariant trainingsets = 5;
    repeated NameVariant sources = 6;
}

message Source {
    string name = 1;
    ResourceStatus status = 2;
    string default_variant = 3;
    repeated string variants = 4;
}

message SourceVariant {
    string name = 1;
    string variant = 2;
    oneof definition {
        Transformation transformation = 14;
        PrimaryData primaryData = 15;
    }
    string owner = 4;
    string description = 5;
    string provider = 6;
    google.protobuf.Timestamp created = 7;
    ResourceStatus status = 8;
    string table = 9;
    repeated NameVariant trainingsets = 10;
    repeated NameVariant features = 11;
    repeated NameVariant labels = 12;
    google.protobuf.Timestamp last_updated = 13;
    string schedule = 16;
}

message Transformation {
    oneof type {
        SQLTransformation SQLTransformation= 1;
        DFTransformation DFTransformation= 2;
    }
}

message SQLTransformation {
    string query = 1;
    repeated NameVariant source = 2;
}

message DFTransformation {
    bytes query = 1;
    repeated NameVariant inputs = 2; 
}

message PrimaryData {
    oneof location {
        PrimarySQLTable table = 1;
    }
}

message PrimarySQLTable {
    string name = 1;
}
