syntax = "proto3";

package flyteidl.core;

option go_package = "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/core";

import "google/protobuf/timestamp.proto";
import "flyteidl/core/identifier.proto";


message ArtifactKey {
  // Project and domain and suffix needs to be unique across a given artifact store.
  string project = 1;
  string domain = 2;
  string name = 3;
  string org = 4;
}

// Only valid for triggers
message ArtifactBindingData {
  reserved 1 to 4;
  // These two fields are only relevant in the partition value case
  oneof partition_data {
    string partition_key = 5;
    bool bind_to_time_partition = 6;
  }

  // This is only relevant in the time partition case
  TimeTransform time_transform = 7;
}

enum Granularity {
  UNSET = 0;
  MINUTE = 1;
  HOUR = 2;
  DAY = 3; // default
  MONTH = 4;
}

enum Operator {
  MINUS = 0;
  PLUS = 1;
}

message TimeTransform {
  string transform = 1;
  Operator op = 2;
}

message InputBindingData {
  string var = 1;
}

message RuntimeBinding {}

message LabelValue {
  oneof value {
    // The string static value is for use in the Partitions object
    string static_value = 1;

    // The time value is for use in the TimePartition case
    google.protobuf.Timestamp time_value = 2;
    ArtifactBindingData triggered_binding = 3;
    InputBindingData input_binding = 4;
    RuntimeBinding runtime_binding = 5;
  }
}

message Partitions {
  map<string, LabelValue> value = 1;
}

message TimePartition {
  LabelValue value = 1;
  Granularity granularity = 2;
}

message ArtifactID {
  ArtifactKey artifact_key = 1;

  string version = 2;

  // Think of a partition as a tag on an Artifact, except it's a key-value pair.
  // Different partitions naturally have different versions (execution ids).
  Partitions partitions = 3;

  // There is no such thing as an empty time partition - if it's not set, then there is no time partition.
  TimePartition time_partition = 4;
}

message ArtifactTag {
  ArtifactKey artifact_key = 1;

  LabelValue value = 2;
}

// Uniqueness constraints for Artifacts
//  - project, domain, name, version, partitions
// Option 2 (tags are standalone, point to an individual artifact id):
//  - project, domain, name, alias (points to one partition if partitioned)
//  - project, domain, name, partition key, partition value
message ArtifactQuery {
  oneof identifier {
    ArtifactID artifact_id = 1;
    ArtifactTag artifact_tag = 2;
    string uri = 3;

    // This is used in the trigger case, where a user specifies a value for an input that is one of the triggering
    // artifacts, or a partition value derived from a triggering artifact.
    ArtifactBindingData binding = 4;
  }
}
