syntax = "proto3";

package NAPS2.Remoting.Worker;

import "Remoting/Error.proto";
import "Serialization/SerializedImage.proto";

service WorkerService {
	rpc Init (InitRequest) returns (InitResponse) {}
	rpc Wia10NativeUi (Wia10NativeUiRequest) returns (Wia10NativeUiResponse) {}
	rpc LoadMapi (LoadMapiRequest) returns (LoadMapiResponse) {}
	rpc SendMapiEmail (SendMapiEmailRequest) returns (SendMapiEmailResponse) {}
	rpc RenderThumbnail (RenderThumbnailRequest) returns (RenderThumbnailResponse) {}
	rpc RenderPdf (RenderPdfRequest) returns (RenderPdfResponse) {}
	rpc ImportPostProcess (ImportPostProcessRequest) returns (ImportPostProcessResponse) {}
	rpc GetDevices (GetDevicesRequest) returns (stream GetDevicesResponse) {}
	rpc GetCaps (GetCapsRequest) returns (GetCapsResponse) {}
	rpc Scan (ScanRequest) returns (stream ScanResponse) {}
	rpc TwainGetDeviceList (GetDeviceListRequest) returns (GetDeviceListResponse) {}
	rpc TwainGetCaps (GetCapsRequest) returns (GetCapsResponse) {}
	rpc TwainScan (TwainScanRequest) returns (stream TwainScanResponse) {}
	rpc StopWorker (StopWorkerRequest) returns (StopWorkerResponse) {}
}

message InitRequest {
	string recoveryFolderPath = 1;
}

message InitResponse {
	NAPS2.Remoting.Error error = 1;
}

message Wia10NativeUiRequest {
	string deviceId = 1;
	fixed64 hwnd = 2;
}

message Wia10NativeUiResponse {
	NAPS2.Remoting.Error error = 1;
	string wiaConfigurationXml = 2;
}

message GetDevicesRequest {
	string optionsXml = 1;
}

message GetDevicesResponse {
	NAPS2.Remoting.Error error = 1;
	string deviceXml = 2;
}

message GetCapsRequest {
	string optionsXml = 1;
}

message GetCapsResponse {
	NAPS2.Remoting.Error error = 1;
	string scanCapsXml = 2;
}

message GetDeviceListRequest {
	string optionsXml = 1;
}

message GetDeviceListResponse {
	NAPS2.Remoting.Error error = 1;
	string deviceListXml = 2;
}

message ScanRequest {
	string optionsXml = 1;
}

message ScanResponse {
	oneof event {
		NAPS2.Remoting.Error error = 1;
		NAPS2.Serialization.SerializedImage image = 2;
		ProgressEvent progress = 3;
		PageStartEvent pageStart = 4;
		DeviceUriChangedEvent deviceUriChanged = 5;
	}
}

message ProgressEvent {
	double value = 1;
}

message PageStartEvent {
}

message DeviceUriChangedEvent {
	string iconUri = 1;
	string connectionUri = 2;
}

message LoadMapiRequest {
	string clientName = 1;
}

message LoadMapiResponse {
	bool loaded = 2;
}

message SendMapiEmailRequest {
	string clientName = 1;
	string emailMessageXml = 2;
}

message SendMapiEmailResponse {
	NAPS2.Remoting.Error error = 1;
	string returnCodeXml = 2;
}

message RenderThumbnailRequest {
	NAPS2.Serialization.SerializedImage image = 1;
	int32 size = 2;
}

message RenderThumbnailResponse {
	NAPS2.Remoting.Error error = 1;
	bytes thumbnail = 2;
}

message RenderPdfRequest {
	string path = 1;
	float dpi = 2;
}

message RenderPdfResponse {
	NAPS2.Remoting.Error error = 1;
	bytes image = 2;
}

message ImportPostProcessRequest {
	NAPS2.Serialization.SerializedImage image = 1;
	int32 thumbnailSize = 2;
	string barcodeDetectionOptionsXml = 3;
}

message ImportPostProcessResponse {
	NAPS2.Remoting.Error error = 1;
	NAPS2.Serialization.SerializedImage image = 2;
}

message StopWorkerRequest {
}

message StopWorkerResponse {
}

message TwainScanRequest {
	string optionsXml = 1;
}

message TwainScanResponse {
	oneof event {
		NAPS2.Remoting.Error error = 1;
		TwainPageStart pageStart = 2;
		TwainNativeImage nativeImage = 3;
		TwainMemoryBuffer memoryBuffer = 4;
		TwainTransferCanceled transferCanceled = 5;
	}
}

message TwainPageStart {
	TwainImageData imageData = 1;
}

message TwainImageData {
	int32 width = 1;
	int32 height = 2;
	int32 bitsPerPixel = 3;
	int32 samplesPerPixel = 4;
	repeated int32 bitsPerSample = 5;
	int32 pixelType = 6;
	double xRes = 7;
	double yRes = 8;
}

message TwainNativeImage {
	bytes buffer = 1;
}

message TwainMemoryBuffer {
	bytes buffer = 1;
	int32 rows = 2;
	int32 columns = 3;
	int32 xOffset = 4;
	int32 yOffset = 5;
	int32 bytesPerRow = 6;
}

message TwainTransferCanceled {
}
