syntax = "proto3";

package openspeak.v1;

import "proto/common.proto";

option go_package = "github.com/sorti/openspeak/pkg/api/openspeak/v1";

service ChannelService {
  rpc CreateChannel(CreateChannelRequest) returns (CreateChannelResponse);
  rpc GetChannel(GetChannelRequest) returns (Channel);
  rpc ListChannels(ListChannelsRequest) returns (ListChannelsResponse);
  rpc UpdateChannel(UpdateChannelRequest) returns (Channel);
  rpc DeleteChannel(DeleteChannelRequest) returns (Status);
  rpc JoinChannel(JoinChannelRequest) returns (JoinChannelResponse);
  rpc LeaveChannel(LeaveChannelRequest) returns (Status);
  rpc ListMembers(ListMembersRequest) returns (ListMembersResponse);
  rpc SubscribeChannelEvents(SubscribeChannelEventsRequest) returns (stream ChannelEvent);
}

message Channel {
  string id = 1;
  string name = 2;
  string description = 3;
  bool is_public = 4;
  string owner_id = 5;
  repeated string member_ids = 6;
  int32 max_users = 7;
  int64 created_at = 8;
  int64 updated_at = 9;
  ChannelStatus status = 10;
}

enum ChannelStatus {
  ACTIVE = 0;
  ARCHIVED = 1;
  DELETED = 2;
}

message CreateChannelRequest {
  string name = 1;
  string description = 2;
  bool is_public = 3;
  int32 max_users = 4;
}

message CreateChannelResponse {
  Status status = 1;
  Channel channel = 2;
}

message GetChannelRequest {
  string channel_id = 1;
}

message ListChannelsRequest {
  PaginationRequest pagination = 1;
  bool include_private = 2;
}

message ListChannelsResponse {
  repeated Channel channels = 1;
  PaginationResponse pagination = 2;
}

message UpdateChannelRequest {
  string channel_id = 1;
  string name = 2;
  string description = 3;
  bool is_public = 4;
  int32 max_users = 5;
}

message DeleteChannelRequest {
  string channel_id = 1;
  bool hard_delete = 2;
}

message JoinChannelRequest {
  string channel_id = 1;
}

message JoinChannelResponse {
  Status status = 1;
  Channel channel = 2;
}

message LeaveChannelRequest {
  string channel_id = 1;
}

message ListMembersRequest {
  string channel_id = 1;
  PaginationRequest pagination = 2;
}

message ListMembersResponse {
  repeated string member_ids = 1;
  PaginationResponse pagination = 2;
}

message SubscribeChannelEventsRequest {
  string channel_id = 1;
}

message ChannelEvent {
  string channel_id = 1;
  string event_type = 2;
  int64 timestamp = 3;
  string user_id = 4;
  map<string, string> data = 5;
}
