syntax = "proto3";
option go_package = "./pb";

package pb;

import "models/model_message_task.proto";
import "models/rpc_messages.proto";

// 消息发送任务服务
service MessageTaskService {
	// 创建消息任务
	rpc createMessageTask (CreateMessageTaskRequest) returns (CreateMessageTaskResponse);

	// 删除消息任务
	rpc deleteMessageTask (DeleteMessageTaskRequest) returns (RPCSuccess);

	// 读取消息任务状态
	rpc findEnabledMessageTask (FindEnabledMessageTaskRequest) returns (FindEnabledMessageTaskResponse);

	// 计算某个状态的消息任务数量
	rpc countMessageTasksWithStatus(CountMessageTasksWithStatusRequest) returns (RPCCountResponse);

	// 根据状态列出某页任务
	rpc listMessageTasksWithStatus(ListMessageTasksWithStatusRequest) returns (ListMessageTasksWithStatusResponse);

	// 发送某个消息任务
	rpc sendMessageTask(SendMessageTaskRequest) returns (SendMessageTaskResponse);

	// 修改消息任务状态
	rpc updateMessageTaskStatus(UpdateMessageTaskStatusRequest) returns (RPCSuccess);
}

// 创建消息任务
message CreateMessageTaskRequest {
	int64 messageRecipientId = 1; // 接收人ID
	int64 messageMediaInstanceId = 2; // 媒介实例ID
	string user = 3; // 用户标识
	string subject = 4; // 标题
	string body = 5; // 内容
	bool isPrimary = 6; // 是否优先发送
}

message CreateMessageTaskResponse {
	int64 messageTaskId = 1; // 消息任务ID
}

// 删除消息任务
message DeleteMessageTaskRequest {
	int64 messageTaskId = 1; // 消息任务ID
}

// 读取消息任务状态
message FindEnabledMessageTaskRequest {
	int64 messageTaskId = 1; // 消息任务ID
}

message FindEnabledMessageTaskResponse {
	MessageTask messageTask = 1; // 消息任务信息
}

// 计算某个状态的消息任务数量
message CountMessageTasksWithStatusRequest {
	Status  status = 1; // 任务状态

	enum Status {
		MessageTaskStatusNone = 0;
		MessageTaskStatusSending = 1;
		MessageTaskStatusSuccess = 2;
		MessageTaskStatusFailed = 3;
	}
}

// 根据状态列出某页任务
message ListMessageTasksWithStatusRequest {
	Status status = 1; // 任务状态
	int64 offset = 2;
	int64 size = 3;

	enum Status {
		MessageTaskStatusNone = 0;
		MessageTaskStatusSending = 1;
		MessageTaskStatusSuccess = 2;
		MessageTaskStatusFailed = 3;
	}
}

message ListMessageTasksWithStatusResponse {
	repeated MessageTask messageTasks = 1;
}

// 发送某个消息任务
// 与创建消息任务放入到后台任务队列不同，此API是直接发送
message SendMessageTaskRequest {
	int64 messageMediaInstanceId = 1; // 媒介实例ID
	string user = 2; // 用户标识
	string subject = 3; // 标题
	string body = 4; // 内容
}

message SendMessageTaskResponse {
	bool isOk = 1; // 是否成功
	string error = 2; // 失败时的提示信息
	string response = 3; // 发送成功后响应内容
}

// 修改消息任务状态
message UpdateMessageTaskStatusRequest {
	int64 messageTaskId = 1; // 消息任务ID
	Status status = 2; // 新的状态

	enum Status {
		MessageTaskStatusNone = 0;
		MessageTaskStatusSending = 1;
		MessageTaskStatusSuccess = 2;
		MessageTaskStatusFailed = 3;
	}
}