syntax = "proto3";

package com.ywt.gapi.im;

option java_multiple_files = true;
option java_package = "com.ywt.gapi.im";
option java_outer_classname = "ImProto";

message SessionMessage {
    int32 from_user_id = 1;
    int32 to_user_id = 2;
    string content = 3;
    string session_id = 4;
    string custom = 5;
    string msg_id = 6;
    int64 time = 7;
    int32 message_type = 8;//消息类型：1 文本消息 2 图片消息 3 病历消息
    string from_user_name = 9;
    string to_user_name = 10;
    int32 from_user_type = 11;
    int32 from_terminal = 12;
}

message NoticeMessage {
    string key_id = 1;
    string title = 2;
    string content = 3;
    int32 send_by = 4;
    string send_by_name = 5;
    string custom = 6;
    int32 type = 7;
    int64 time = 8;
    int32 to_user_id = 9;
    string session_id = 10;
    string to_user_name = 11;
}

message SendResponse {
    int32 code = 1;
}

message PullSessionMessageRecordRequest {
    int32 user_id = 1;
    int32 to_user_id = 2;
    string session_id = 3;
    int64 time = 4;
    int32 count = 5;
}

message SessionMessageRecordResponse {
    int32 code = 1;
    repeated SessionMessage datas = 2;
}

message PullNoticeMessageRequest {
    int32 user_id = 1;
    int64 time = 2;
    int32 count = 3;
}

message NoticeMessageResponse {
    int32 code = 1;
    repeated NoticeMessage datas = 2;
}

//签发JWT请求消息
message IssueTokenRequest {
    string authData = 1; //授权数据
}
//签发JWT响应消息
message IssueTokenResponse {
    int32 code = 1;
    string msg = 2;
    string token = 3;
}
//验证JWT请求消息
message CheckTokenRequest {
    string token = 1;
}
//验证JWT响应消息
message CheckTokenResponse {
    int32 code = 1;
    string msg = 2;
    int32 checkResult = 3; // 1 : 验证通过; 2 : 验证失败
    string authData = 4;
}
//保存会话消息请求消息
message SaveSessionMessageRequest {
    int32 from_user_id = 1;
    string from_user_name = 2;
    int32 to_user_id = 3;
    string to_user_name = 4;
    int32 message_type = 5;
    string content = 6;
    string session_id = 7;
    string msg_id = 8;
    int64 time = 9;
    string custom = 10;
    int32 from_user_type = 11;
    int32 from_terminal = 12;
}
//保存会话消息响应消息
message SaveSessionMessageResponse {
    int32 code = 1;
    string msg = 2;
}
//保存通知数据请求消息
message SaveNoticeMessageRequest {
    string key_id = 1;
    string title = 2;
    string content = 3;
    int32 send_by = 4;
    string send_by_name = 5;
    string custom = 6;
    int32 type = 7;
    int64 time = 8;
    string session_id = 9;
    int32 user_id = 10;
}
//保存通知数据响应消息
message SaveNoticeMessageResponse {
    int32 code = 1;
    string msg = 2;
}
//撤回消息请求
message RecallRequest{
    string msg_id = 1;
    int32 from_user_id = 2;
    string from_user_name = 3;
    int32 to_user_id = 4;
    string to_user_name = 5;
    string session_id = 6;
    int32 message_type = 7;
}
//撤回消息响应
message RecallResponse {
    int32 code = 1;
    string msg = 2;
}

//会话数统计
message SessionCountRequest{
    string session_id = 1;
}

message SessionCountResponse{
    int32 code = 1;
    string msg = 2;
    int32 total = 3;
}

message GetChatsRequest {
    int32 user_id = 1;
    int32 to_user_id = 2;
    string session_id = 3;
    int64 time = 4;         //结束时间
    int32 count = 5;
    int64 start_time = 6;   //起始时间
    int32 messageType = 7;
}

message GetChatsResponse {
    int32 code = 1;
    repeated SessionMessage datas = 2;
}

message NotifyNewPublishForDocRequest {
    int32 articleId = 1;
    repeated int32 toDoctorIds = 2;
    bool toAllDoctor = 3;
}

// update 参数，支持 content, custom 等
message UpdateStringParam {
    string key = 1;
    string value = 2;
}

message UpdateMsgRequest {
    string msgId = 1;
    repeated UpdateStringParam updateStringParams = 2;
}

message UpdateMsgResponse {
    int32 code = 1;
    string msg = 2;
}

// 对应 imserver 项目 IMCloudServer.js 文件
service IMService {
    rpc sendNoticeMessage(NoticeMessage) returns (SendResponse); //发送通知消息
    rpc sendSessionMessage(SessionMessage) returns (SendResponse); //发送会话消息
    rpc pullSessionMessageRecord(PullSessionMessageRecordRequest) returns (SessionMessageRecordResponse); //拉取聊天记录
    rpc pullNoticeMessage(PullNoticeMessageRequest) returns (NoticeMessageResponse); //拉取消息中心
    rpc issueToken(IssueTokenRequest) returns (IssueTokenResponse); //签发JWT
    rpc checkToken(CheckTokenRequest) returns (CheckTokenResponse); //验证JWT
    rpc saveSessionMessage(SaveSessionMessageRequest) returns (SaveSessionMessageResponse); //保存会话数据
    rpc saveNoticeMessage(SaveNoticeMessageRequest) returns (SaveNoticeMessageResponse); //保存通知数据
    rpc recall(RecallRequest) returns (RecallResponse);//撤回消息
    rpc sessionCount(SessionCountRequest) returns (SessionCountResponse);//会话数统计
    rpc getChats(GetChatsRequest) returns (GetChatsResponse);//获取聊天记录
    rpc notifyNewPublishForDoc(NotifyNewPublishForDocRequest) returns (SendResponse);//推送新发表文章到医生 PC 端
    rpc updateSessionMsg(UpdateMsgRequest) returns (UpdateMsgResponse);
}

message AliSendSMSRequest {
	string phoneNumbers = 1;
	string signName = 2;
	string templateCode = 3;
	string templateParam = 4;
	string outId = 5;
}

message AliSendSMSResponse {
	int32 code = 1;
	string requestId = 2;
	string message = 3;
	string bizId = 4;
}
//阿里短讯代理服务  // 目前不用了，采用诚立业的了,对应 base-service 项目 --> provider -->sms.js 文件
service AliSMSProxyService {
	rpc sendSMS(AliSendSMSRequest) returns (AliSendSMSResponse);
}
