// Copyright 2021 The Kubeflow Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

option go_package = "github.com/kubeflow/pipelines/backend/api/v1beta1/go_client";
package api;

import "google/api/annotations.proto";
import "google/protobuf/timestamp.proto";
import "backend/api/v1beta1/resource_reference.proto";

message Task {
  // Output. Unique task ID. Generated by API server.
  string id = 1;

  // Optional input field. The Namespace to which this pipeline task belongs.
  string namespace = 2;

  // Required input field. The PipelineName to which this pipeline task belongs.
  // Namespace will be encoded in the PipelineName.
  // "namespace/${namespace}/pipeline/${pipelineName}" for namespaced pipelines
  // "pipeline/${pipelineName}" for shared pipelines
  string pipelineName = 3;

  // Required input field.The ID of the PipelineRun that the PipelineTask belongs to.
  string runId = 4;

  // Required input field. The ID of the MLMD execution associated with the PipelineTask.
  string mlmdExecutionID = 5;

  // Required input field. The time this task is created.
  google.protobuf.Timestamp created_at = 6;

  // Optional input field. The time this task is finished.
  google.protobuf.Timestamp finished_at = 7;

  // Required input field.
  string fingerprint = 8;
}

service TaskService {
  // Creates a new task.
  rpc CreateTaskV1(CreateTaskRequest) returns (Task) {
    option (google.api.http) = {
      post: "/apis/v1alpha1/tasks"
      body: "task"
    };
  }

  // Finds all tasks. Supports pagination, and sorting on certain fields.
  rpc ListTasksV1(ListTasksRequest) returns (ListTasksResponse) {
    option (google.api.http) = {
      get: "/apis/v1alpha1/tasks"
    };
  }
}

message CreateTaskRequest {
  Task task = 1;
}

message ListTasksRequest {
  // A page token to request the next page of results. The token is acquried
  // from the nextPageToken field of the response from the previous
  // ListExperiment call or can be omitted when fetching the first page.
  string page_token = 1;

  // The number of experiments to be listed per page. If there are more
  // experiments than this number, the response message will contain a
  // nextPageToken field you can use to fetch the next page.
  int32 page_size = 2;

  // Can be format of "field_name", "field_name asc" or "field_name desc"
  // Ascending by default.
  string sort_by = 3;

  // What resource reference to filter on.
  // E.g. If listing tasks for an pipeline run, the query string would be
  // resource_reference_key.type="PIPELINE"&resource_reference_key.id=123
  ResourceKey resource_reference_key = 4;

  // A url-encoded, JSON-serialized Filter protocol buffer (see
  // [filter.proto](https://github.com/kubeflow/pipelines/blob/master/backend/api/v1beta1/filter.proto)).
  string filter = 5;


}

message ListTasksResponse {
  // A list of tasks returned.
  repeated Task tasks = 1;

  // The token to list the next page of experiments.
  string next_page_token = 2;

  // The total number of experiments for the given query.
  int32 total_size = 3;
}
