syntax = "proto3";

package ccim.protocol;

import "channel.proto";
import "common.proto";
import "contact.proto";
import "message.proto";
import "push.proto";
import "user.proto";

message ChatRequestMessage {
    RequestMessageHeader header = 1;

    oneof payload {
        ConnectRequest connect_req = 2;                             // 连接
        PullContactsRequest pull_contacts_req = 3;                  // 拉联系人
        SearchRequest search_req = 4;                               // 查找用户
        AddContactRequest add_contact_req = 5;                      // 添加联系人
        ContactRequestsRequest contact_requests_req = 6;            // 联系人申请列表
        CheckContactReqRequest check_contact_req_req = 7;           // 验证联系人申请
        CreateContactGroupRequest create_contact_group_req = 8;     // 创建联系人组
        MoveContactGroupRequest move_contact_group_req = 9;         // 移动联系人所在组
        DeleteContactGroupRequest delete_contact_group_req = 10;    // 删除联系人组
        DeleteContactRequest delete_contact_req = 11;               // 删除联系人
        PullOfflineMessageRequest pull_offline_msg_req = 12;        // 拉取离线消息

        CreateChannelRequest create_channel_req = 21;               // 创建频道
        JoinChannelRequest join_channel_req = 22;                   // 加入频道
        RemoveMemberRequest remove_member_req = 23;                 // 移除成员
        ExitChannelRequest exit_channel_req = 24;                   // 退出频道
        ChannelBlockUserRequest channel_block_user_req = 25;        // 拉黑频道成员

        ReportIllegalUserRequest report_illegal_user_req = 31;      // 举报违规用户
        BlockUserRequest block_user_req = 32;                       // 用户拉入黑名单
        PreUploadSignRequest pre_upload_sign_req = 33;              // 预上传获取签名

        SendMessageRequest send_msg_req = 42;                       // 发送消息
        SendChannelMessageRequest send_channel_msg_req = 43;        // 发送频道消息

        PushPrivateMessageAckRequest push_private_msg_ack_req = 61; // 推送私人消息成功ack
        PushChannelMessageAckRequest push_channel_msg_ack_req = 62; // 推送频道消息ack

        PullPrivateMessageRequest pull_private_msg_req = 81;        // 拉取私聊消息
        PullChannelMessageRequest pull_channel_msg_req = 82;        // 拉取频道消息

        HeartbeatRequest heartbeat_req = 100;                       // 作用于登录返回的心跳间隔heartbeat_interval
        ConnectionStateAckRequest connection_state_ack_req = 101;   // 服务端主动返回一个ConnectionStateResponse时客户端必须返回ConnectionStateAckRequest
    }
};

message ChatResponseMessage {
    ResponseMessageHeader header = 1;

    oneof payload {
        ConnectResponse connect_res = 2;
        PullContactsResponse pull_contacts_res = 3;
        SearchResponse search_res = 4;
        AddContactResponse add_contact_res = 5;
        ContactRequestsResponse contact_requests_res = 6;
        CheckContactReqResponse check_contact_req_res = 7;
        CreateContactGroupResponse create_contact_group_res = 8;
        MoveContactGroupResponse move_contact_group_res = 9;
        DeleteContactGroupResponse delete_contact_group_res = 10;
        DeleteContactResponse delete_contact_res = 11;
        PullOfflineMessageResponse pull_offline_msg_res = 12;

        CreateChannelResponse create_channel_res = 21;
        JoinChannelResponse join_channel_res = 22;
        RemoveMemberResponse remove_member_res = 23;
        ExitChannelResponse exit_channel_res = 24;
        ChannelBlockUserResponse channel_block_user_res = 25;

        ReportIllegalUserResponse report_illegal_user_res = 31;
        BlockUserResponse block_user_res = 32;
        PreUploadSignResponse pre_upload_sign_res = 33;

        SendMessageResponse send_msg_res = 41;
        SendChannelMessageResponse send_channel_msg_res = 42;

        PushPrivateMessageResponse push_private_msg_res = 61;
        PushChannelMessageResponse push_channel_msg_res = 62;

        PushContactDeleteMeResponse push_contact_delete_me_res = 71;    // 推送联系人删除了我
        PushNewContactResponse push_new_contact_res = 72;               // 推送有新的联系人
        PushContactNetStatusResponse push_contact_net_status_res = 73;  // 推送联系人网络状态
        PushContactNewReqResponse push_contact_new_req_res = 74;        // 推送新的好友申请
        PushUserDeletedResponse push_user_deleted_res = 76;             // 推送与自己有关系(对话过的陌生人或好友)的用户已删除

        PullPrivateMessageResponse pull_private_msg_res = 81;           // 拉取私聊消息
        PullChannelMessageResponse pull_channel_msg_res = 82;           // 拉取频道消息

        HeartbeatResponse heartbeat_res = 100;
        ConnectionStateResponse connection_state_res = 101;
    }
};

message ConnectRequest {
    string app_key = 1;
    int64 user_id = 2;
    string username = 3;
    string ext_data = 4;
    int64 ts = 5;
    string sign = 6;

    string game_server = 7;
    // sign使用HMAC加密算法，由接入端的服务端计算完成传给接入端的客户端
    // sign = HMAC_SHA256(app_secret).digestToHex(app_key&user_id&username&game_server&ext_data&ts&app_secret)
    // ts=CurrentTimeMillis (毫秒)
}

message ConnectResponse {
    message ClientConfig {
        int32 send_msg_interval = 1;
        int32  max_audio_duration = 2;
        string download_prefix = 3;     // 下载地址前缀
    }
    bool connected = 1;                 //是否连接成功
    int32 heart_beat_interval = 2;
    ClientConfig client_cfg = 3;        //客户端配置
}

message PullContactsRequest {}

message PullContactsResponse {
    message ContactGroup {
        int64 group_id = 1;         // 群组id
        string name = 2;            // 群组名称
    }
    message Channel {
        int64 channel_id = 1;
        int64 app_id = 2;
        int64 owner_user_id = 3;
        int32 limited = 4;
        bool muted = 5;
        string name = 6;
        string ext_data = 7;
    }
    repeated ContactGroup contact_groups = 2;   // 联系人群组列表
    repeated Contact contacts = 3;              // 联系人列表
    repeated Dialog dialogs = 4;                // 对话列表
    repeated int64 blocklist = 5;               // 黑名单
}

message SearchRequest {
    string username = 1;
    int64 user_id = 2;
    int32 page = 3;
    int32 size = 4;
}

message SearchResponse {
    message User {
        int64 user_id = 1;
        string username = 2;
        string ext_data = 3;
    }
    repeated User users = 1;
    int32 total = 2;
}

message AddContactRequest {
    int64 user_id = 1;
}

message ContactRequestsRequest {}

message ContactRequestsResponse {
    repeated ContactReqData requests = 1;
}

message CheckContactReqRequest {
    bool accept = 1;
    int64 req_user_id = 2;
}

message CheckContactReqResponse {
    Contact new_contact = 1;
}

message CreateContactGroupRequest {
    string name = 1;
}

message CreateContactGroupResponse {
    int64 group_id = 1;
}

message MoveContactGroupRequest {
    int64 contact_user_id = 1;
    int64 contact_group_id = 2;
}

message MoveContactGroupResponse {
}

message DeleteContactRequest {
    int64 contact_user_id = 1;
}

message DeleteContactResponse {
}

message ReportIllegalUserRequest {
    int64 illegal_user_id = 1;
    string title = 2;
    string content = 3;
}

message ReportIllegalUserResponse {}

message HeartbeatRequest {
}

message HeartbeatResponse {
}

message ConnectionStateAckRequest {}

message ConnectionStateResponse {
}