syntax = "proto3";

package pb;

option go_package = "./pb";

// ------------------------------------
// Messages
// ------------------------------------

//--------------------------------chatSessions--------------------------------
message ChatSessions {
  int64 id = 1; //id
  string type = 2; //type: group, dm
  string name = 3; //name
  int64 creatorId = 4; //creatorId
  repeated int64 participants = 5; //participants
  string lastMessage = 6; //lastMessage
  int64 lastMessageAt = 7; //lastMessageAt
  int64 createdAt = 8; //createdAt
  int64 updatedAt = 9; //updatedAt
}

message AddChatSessionsReq {
  string type = 1; //type: group, dm
  string name = 2; //name
  int64 creatorId = 3; //creatorId
  repeated int64 participants = 4; //participants
}

message AddChatSessionsResp {
  int64 id = 1; //id
}

message UpdateChatSessionsReq {
  int64 id = 1; //id
  optional string name = 2; //name
  optional string lastMessage = 3; //lastMessage
  optional int64 lastMessageAt = 4; //lastMessageAt
}

message UpdateChatSessionsResp {}

message DelChatSessionsReq {
  int64 id = 1; //id
}

message DelChatSessionsResp {}

message GetChatSessionsByIdReq {
  int64 id = 1; //id
}

message GetChatSessionsByIdResp {
  ChatSessions chatSessions = 1; //chatSessions
}

message SearchChatSessionsReq {
  int64 page = 1; //page
  int64 limit = 2; //limit
  optional int64 userId = 3; //userId (filter sessions containing this user)
  optional string type = 4; //type
}

message SearchChatSessionsResp {
  repeated ChatSessions chatSessions = 1; //chatSessions
}

message AddParticipantReq {
  int64 sessionId = 1; //sessionId
  int64 userId = 2; //userId
}

message AddParticipantResp {}

message RemoveParticipantReq {
  int64 sessionId = 1; //sessionId
  int64 userId = 2; //userId
}

message RemoveParticipantResp {}

//--------------------------------chatMessages--------------------------------
message ChatMessages {
  int64 id = 1; //id
  int64 sessionId = 2; //sessionId
  int64 senderId = 3; //senderId
  string type = 4; //type: text, image, system
  string content = 5; //content
  int64 createdAt = 6; //createdAt
}

message AddChatMessagesReq {
  int64 sessionId = 1; //sessionId
  int64 senderId = 2; //senderId
  string type = 3; //type
  string content = 4; //content
}

message AddChatMessagesResp {
  int64 id = 1; //id
}

message DelChatMessagesReq {
  int64 id = 1; //id
}

message DelChatMessagesResp {}

message GetChatMessagesByIdReq {
  int64 id = 1; //id
}

message GetChatMessagesByIdResp {
  ChatMessages chatMessages = 1; //chatMessages
}

message SearchChatMessagesReq {
  int64 page = 1; //page
  int64 limit = 2; //limit
  int64 sessionId = 3; //sessionId
  optional int64 senderId = 4; //senderId
}

message SearchChatMessagesResp {
  repeated ChatMessages chatMessages = 1; //chatMessages
}

// ------------------------------------
// Rpc Func
// ------------------------------------

service chatService {
  //-----------------------chatSessions-----------------------
  rpc AddChatSessions(AddChatSessionsReq) returns (AddChatSessionsResp);
  rpc UpdateChatSessions(UpdateChatSessionsReq) returns (UpdateChatSessionsResp);
  rpc DelChatSessions(DelChatSessionsReq) returns (DelChatSessionsResp);
  rpc GetChatSessionsById(GetChatSessionsByIdReq) returns (GetChatSessionsByIdResp);
  rpc SearchChatSessions(SearchChatSessionsReq) returns (SearchChatSessionsResp);
  rpc AddParticipant(AddParticipantReq) returns (AddParticipantResp);
  rpc RemoveParticipant(RemoveParticipantReq) returns (RemoveParticipantResp);
  //-----------------------chatMessages-----------------------
  rpc AddChatMessages(AddChatMessagesReq) returns (AddChatMessagesResp);
  rpc DelChatMessages(DelChatMessagesReq) returns (DelChatMessagesResp);
  rpc GetChatMessagesById(GetChatMessagesByIdReq) returns (GetChatMessagesByIdResp);
  rpc SearchChatMessages(SearchChatMessagesReq) returns (SearchChatMessagesResp);
}
