/*
	Copyright The containerd 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";

package containerd.services.diff.v1;

import "google/protobuf/any.proto";
import "google/protobuf/timestamp.proto";
import "github.com/containerd/containerd/api/types/mount.proto";
import "github.com/containerd/containerd/api/types/descriptor.proto";

option go_package = "github.com/containerd/containerd/api/services/diff/v1;diff";

// Diff service creates and applies diffs
service Diff {
	// Apply applies the content associated with the provided digests onto
	// the provided mounts. Archive content will be extracted and
	// decompressed if necessary.
	rpc Apply(ApplyRequest) returns (ApplyResponse);

	// Diff creates a diff between the given mounts and uploads the result
	// to the content store.
	rpc Diff(DiffRequest) returns (DiffResponse);
}

message ApplyRequest {
	// Diff is the descriptor of the diff to be extracted
	containerd.types.Descriptor diff = 1;

	repeated containerd.types.Mount mounts = 2;

	map<string, google.protobuf.Any> payloads = 3;
	// SyncFs is to synchronize the underlying filesystem containing files.
	bool sync_fs = 4;
}

message ApplyResponse {
	// Applied is the descriptor for the object which was applied.
	// If the input was a compressed blob then the result will be
	// the descriptor for the uncompressed blob.
	containerd.types.Descriptor applied = 1;
}

message DiffRequest {
	// Left are the mounts which represent the older copy
	// in which is the base of the computed changes.
	repeated containerd.types.Mount left = 1;

	// Right are the mounts which represents the newer copy
	// in which changes from the left were made into.
	repeated containerd.types.Mount right = 2;

	// MediaType is the media type descriptor for the created diff
	// object
	string media_type = 3;

	// Ref identifies the pre-commit content store object. This
	// reference can be used to get the status from the content store.
	string ref = 4;

	// Labels are the labels to apply to the generated content
	// on content store commit.
	map<string, string> labels = 5;

	// SourceDateEpoch specifies the timestamp used for whiteouts to provide control for reproducibility.
	// See also https://reproducible-builds.org/docs/source-date-epoch/ .
	google.protobuf.Timestamp source_date_epoch = 6;
}

message DiffResponse {
	// Diff is the descriptor of the diff which can be applied
	containerd.types.Descriptor diff = 3;
}
