syntax = "proto3";

package yandex.cloud.datasphere.v1;

import "google/api/annotations.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/wrappers.proto";
import "yandex/cloud/api/operation.proto";
import "yandex/cloud/validation.proto";
import "yandex/cloud/operation/operation.proto";
import "yandex/cloud/datasphere/v1/project.proto";

option go_package = "github.com/yandex-cloud/go-genproto/yandex/cloud/datasphere/v1;datasphere";
option java_package = "yandex.cloud.api.datasphere.v1";

// A set of methods for managing Project resources.
service ProjectService {
    // Creates a project in the specified folder.
    rpc Create (CreateProjectRequest) returns (operation.Operation) {
        option (google.api.http) = { post: "/datasphere/v1/projects" body: "*" };
        option (yandex.cloud.api.operation) = {
            metadata: "CreateProjectMetadata"
            response: "Project"
        };
    }

    // Updates the specified project.
    rpc Update (UpdateProjectRequest) returns (operation.Operation) {
        option (google.api.http) = { patch: "/datasphere/v1/projects/{project_id}" body: "*" };
        option (yandex.cloud.api.operation) = {
            metadata: "UpdateProjectMetadata"
            response: "Project"
        };
    }

    // Deletes the specified project.
    rpc Delete (DeleteProjectRequest) returns (operation.Operation) {
        option (google.api.http) = { delete: "/datasphere/v1/projects/{project_id}" };
        option (yandex.cloud.api.operation) = {
            metadata: "DeleteProjectMetadata"
            response: "google.protobuf.Empty"
        };
    }

    // Opens the specified project.
    rpc Open (OpenProjectRequest) returns (operation.Operation) {
        option (google.api.http) = { post: "/datasphere/v1/projects/{project_id}:open" };
        option (yandex.cloud.api.operation) = {
            metadata: "OpenProjectMetadata"
            response: "OpenProjectResponse"
        };
    }

    // Returns the specified project.
    rpc Get (GetProjectRequest) returns (Project) {
        option (google.api.http) = { get: "/datasphere/v1/projects/{project_id}" };
    }

    // Lists projects for the specified folder.
    rpc List (ListProjectsRequest) returns (ListProjectsResponse) {
        option (google.api.http) = { get: "/datasphere/v1/projects" };
    }

    // Returns the unit balance of the specified project.
    rpc GetUnitBalance (GetUnitBalanceRequest) returns (GetUnitBalanceResponse) {
        option (google.api.http) = { get: "/datasphere/v1/projects/{project_id}:unitBalance" };
    }

    //  Sets the unit balance of the specified project.
    rpc SetUnitBalance (SetUnitBalanceRequest) returns (google.protobuf.Empty) {
        option (google.api.http) = { post: "/datasphere/v1/projects/{project_id}:unitBalance" body: "*" };
    }
}

message CreateProjectRequest {
    // ID of the folder to create a project in.
    // To get the folder ID use a [yandex.cloud.resourcemanager.v1.FolderService.List] request.
    string folder_id = 1 [(required) = true, (length) = "<=50"];

    // Name of the project.
    string name = 2 [(length) = "<=63", (pattern) = "[a-z]([-a-z0-9]{0,61}[a-z0-9])?"];

    // Description of the project.
    string description = 3 [(length) = "<=256"];

    // Settings of the project.
    Project.Settings settings = 4;

    // Limits of the project.
    Project.Limits limits = 5;
}

message CreateProjectMetadata {
    // ID of the project that is being created.
    string project_id = 1;
}

message UpdateProjectRequest {
    // ID of the Project resource to update.
    // To get the project ID use a [ProjectService.List] request.
    string project_id = 1 [(required) = true, (length) = "<=200"];

    // Field mask that specifies which fields of the Project resource are going to be updated.
    google.protobuf.FieldMask update_mask = 2;

    // Name of the project.
    string name = 3 [(length) = "<=63", (pattern) = "[a-z]([-a-z0-9]{0,61}[a-z0-9])?"];

    // Description of the project.
    string description = 4 [(length) = "<=256"];

    // Settings of the project.
    Project.Settings settings = 5;

    // Limits of the project.
    Project.Limits limits = 6;
}

message UpdateProjectMetadata {
    // ID of the project that is being updated.
    string project_id = 1;
}

message DeleteProjectRequest {
    // ID of the Project resource to delete.
    // To get the project ID use a [ProjectService.List] request.
    string project_id = 1 [(required) = true, (length) = "<=200"];
}

message DeleteProjectMetadata {
    // ID of the project that is being deleted.
    string project_id = 1;
}

message OpenProjectRequest {
    // ID of the Project resource to open.
    // To get the project ID use a [ProjectService.List] request.
    string project_id = 1 [(required) = true, (length) = "<=200"];
}

message OpenProjectMetadata {
    // ID of the project that is being opened.
    string project_id = 1;
}

message OpenProjectResponse {
    // URL of the project that is being opened.
    // Make GET request to [project_url] with sessionToken query parameter equals to [session_token]
    // or POST request to [project_url] with sessionToken body parameter equals to [session_token]
    // to fetch Datasphere web interface.
    string project_url = 1;
    // Session token of the project that is being opened.
    string session_token = 2;
}

message GetProjectRequest {
    // ID of the Project resource to return.
    // To get the project ID use a [ProjectService.List] request.
    string project_id = 1 [(required) = true, (length) = "<=200"];
}

message ListProjectsRequest {
    // ID of the folder to list projects in.
    // To get the folder ID use a [yandex.cloud.resourcemanager.v1.FolderService.List] request.
    string folder_id = 1 [(required) = true, (length) = "<=50"];

    // The maximum number of results per page to return. If the number of available
    // results is larger than [page_size],
    // the service returns a [ListProjectsResponse.next_page_token]
    // that can be used to get the next page of results in subsequent list requests.
    int64 page_size = 2 [(value) = "0-1000"];

    // Page token. To get the next page of results, set [page_token] to the
    // [ListProjectsResponse.next_page_token] returned by a previous list request.
    string page_token = 3 [(length) = "<=100"];
}

message ListProjectsResponse {
    // List of Project resources.
    repeated Project projects = 1;

    // This token allows you to get the next page of results for list requests. If the number of results
    // is larger than [ListProjectsRequest.page_size], use
    // the [next_page_token] as the value
    // for the [ListProjectsRequest.page_token] query parameter
    // in the next list request. Each subsequent list request will have its own
    // [next_page_token] to continue paging through the results.
    string next_page_token = 2;
}

message GetUnitBalanceRequest {
    // ID of the project to return the unit balance for.
    string project_id = 1 [(required) = true, (length) = "<=200"];
}

message GetUnitBalanceResponse {
    // The number of units available to the project.
    google.protobuf.Int64Value unit_balance = 1;
}

message SetUnitBalanceRequest {
    // ID of the project to set the unit balance for.
    string project_id = 1 [(required) = true, (length) = "<=200"];

    // The number of units available to the project.
    google.protobuf.Int64Value unit_balance = 2;
}
