syntax = "proto3";



enum FileAckType {
    FILE_ABORT = 0;
    FILE_RECEIVE_STATUS = 1;
    PARENT_NO_DATA = 2;
}
option java_package = "com.afreecatv.mobile.sdk.proto";
option java_outer_classname = "header";

enum RTCConnectionChangeType {
    DISCONNECT_CONNECTION = 0;

    // 양쪽에서 동시에 같은 커넥션을 제거할 경우를 방지
    // 상대방 피어한테 커넥션 더 열어도 돼? 물어보는 과정
    INCREASE_CONNECTION_CHECK = 1;
    INCREASE_CONNECTION = 3;

    DECREASE_CONNECTION_CHECK = 4;
    DECREASE_CONNECTION = 6;

    INCREASE_DATA_CHANNEL_CHECK = 7;
    INCREASE_DATA_CHANNEL = 9;

    DECREASE_DATA_CHANNEL_CHECK = 10;
    DECREASE_DATA_CHANNEL = 12;
}


// 놀랍게도 SdkStreamHeader에는 SdkStreamID를 포함하지 않으니 참고바람.
message SdkStreamHeader {
    oneof packet {
        FileRequest file_request = 1;
        FileResponse file_response = 2;
        FileAck file_ack = 3;
        SdkStreamRequest sdk_stream_request = 4;
        SdkStreamResponse sdk_stream_response = 5;
        SdkStreamAck sdk_stream_ack = 6;
        SdkRTCConnectionChangeRequest sdk_rtc_connection_change_request = 7;
        SdkRTCConnectionChangeResponse sdk_rtc_connection_change_response = 8;
        PeerPing peer_ping = 9;
        PeerPong peer_pong = 10;
    }
}

message KeyValPair {
    string key = 1;
    bytes value = 2;
}

message FileRequest {
    uint32 file_request_id = 1;
    repeated KeyValPair header = 2;

    // 부득이하게 헤더 안에다가 파일을 추가해야 할 경우 사용. (FileResponse도 마찬가지)
    // 가급적이면 데이터는 SdkStreamHeader 뒤에다 붙여서 전달하길 권장함
    optional bytes payload = 3;
}

message FileResponse {
    uint32 file_request_id = 1;
    string name = 2;
    uint64 size = 3;
    string mimeType = 4;
    string label = 5;

    repeated KeyValPair header = 10;
    bytes data = 20;
}

// 이거 SDKPacket ack항목으로 대체될 예정
message FileAck {
    uint32 file_request_id = 1;
    FileAckType type = 2;
    string label = 3;
    repeated KeyValPair header = 10;
}

message SdkStreamRequest {
    uint32 stream_request_id = 1;
    string label = 2;
    repeated KeyValPair header = 10;
}

message SdkStreamResponse {
    uint32 stream_request_id = 1;
    string label = 2;
    repeated KeyValPair header = 10;
}

message SdkStreamAck {
    uint32 stream_request_id = 1;
    repeated KeyValPair header = 3;
}

message SdkRTCConnectionChangeRequest {
    RTCConnectionChangeType type = 1;
    uint32 request_peer_id = 2;
    uint32 response_peer_id = 3;
    string data_channel_name = 4;
    uint32 data_channel_count = 5;
    repeated KeyValPair header = 100;
}

message SdkRTCConnectionChangeResponse {
    RTCConnectionChangeType type = 1;
    uint32 request_peer_id = 2;
    uint32 response_peer_id = 3;
    string data_channel_name = 4;
    uint32 data_channel_count = 5;
    int32 result = 6;
    repeated KeyValPair header = 100;
}

message PeerPing {
    uint32 ping_id = 1;
    uint32 request_peer_id = 2;
    uint32 response_peer_id = 3;
    uint32 uploadSize = 4; // 보낼 데이터 크기
    uint32 downloadSize = 5; // 상대방이 나에게 보내줄 데이터 크기
    optional bytes payload = 6;
}

message PeerPong {
    uint32 ping_id = 1;
    uint32 request_peer_id = 2;
    uint32 response_peer_id = 3;
    uint32 uploadSize = 4; // upload 받은 데이터 크기
    uint32 downloadSize = 5; // download로 전달할 데이터 크기
    optional bytes data = 6;
}