// Path: app/src/main/java/com/arexperiments/justaline/model/RoomData.java
// public class RoomData {
// 
//     public String key;
// 
//     private Long timestamp;
// 
//     private Message message;
// 
//     public RoomData(String key, Long timestamp) {
//         this.key = key;
//         this.timestamp = timestamp;
// 
//         String messageString = key + "," + timestamp.toString();
//         message = new Message(messageString.getBytes());
//     }
// 
//     public RoomData(Message message) {
//         this.message = message;
//         String messageString = new String(message.getContent());
//         String[] parts = messageString.split(",");
//         if (parts.length == 2) {
//             try {
//                 key = parts[0];
//                 timestamp = Long.parseLong(parts[1]);
//             } catch (RuntimeException e) {
//                 throw new MalformedDataException(
//                         "Message does not meet format <int:code>,<long:timestamp>: "
//                                 + messageString);
//             }
//         } else {
//             throw new MalformedDataException(
//                     "Message does not meet format <code>,<timestamp>: " + messageString);
//         }
//     }
// 
//     public Message getMessage() {
//         return message;
//     }
// 
//     public String getKey() {
//         return key;
//     }
// 
//     public static class MalformedDataException extends RuntimeException {
// 
//         public MalformedDataException(String message) {
//             super(message);
//         }
//     }
// }


import android.content.Context;
import android.util.Log;
import com.arexperiments.justaline.model.RoomData;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.arexperiments.justaline;



/**
 * Created by Kat on 4/10/18.
 */

public class GlobalRoomManager extends RoomManager {

    private static final String TAG = "GlobalRoomManager";

    private static String ROOT_GLOBAL_ROOM = "global_rooms/global_room";

    private static String globalRoomName = "";

    private DatabaseReference globalRoomRef;

    private GlobalRoomListener globalRoomListener;

    /**
     * Default constructor for the FirebaseManager class.
     *
     * @param context The application context.
     */
    public GlobalRoomManager(Context context) {
        super(context);
    }

    public static void setGlobalRoomName(String name) {
        Log.i(TAG, "Set global room name: " + name);
        globalRoomName = name;
    }

    @Override
// Path: app/src/main/java/com/arexperiments/justaline/model/RoomData.java
// public class RoomData {
// 
//     public String key;
// 
//     private Long timestamp;
// 
//     private Message message;
// 
//     public RoomData(String key, Long timestamp) {
//         this.key = key;
//         this.timestamp = timestamp;
// 
//         String messageString = key + "," + timestamp.toString();
//         message = new Message(messageString.getBytes());
//     }
// 
//     public RoomData(Message message) {
//         this.message = message;
//         String messageString = new String(message.getContent());
//         String[] parts = messageString.split(",");
//         if (parts.length == 2) {
//             try {
//                 key = parts[0];
//                 timestamp = Long.parseLong(parts[1]);
//             } catch (RuntimeException e) {
//                 throw new MalformedDataException(
//                         "Message does not meet format <int:code>,<long:timestamp>: "
//                                 + messageString);
//             }
//         } else {
//             throw new MalformedDataException(
//                     "Message does not meet format <code>,<timestamp>: " + messageString);
//         }
//     }
// 
//     public Message getMessage() {
//         return message;
//     }
// 
//     public String getKey() {
//         return key;
//     }
// 
//     public static class MalformedDataException extends RuntimeException {
// 
//         public MalformedDataException(String message) {
//             super(message);
//         }
//     }
// }


// Path: app/src/main/java/com/arexperiments/justaline/GlobalRoomManager.java
import android.content.Context;
import android.util.Log;
import com.arexperiments.justaline.model.RoomData;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.arexperiments.justaline;



/**
 * Created by Kat on 4/10/18.
 */

public class GlobalRoomManager extends RoomManager {

    private static final String TAG = "GlobalRoomManager";

    private static String ROOT_GLOBAL_ROOM = "global_rooms/global_room";

    private static String globalRoomName = "";

    private DatabaseReference globalRoomRef;

    private GlobalRoomListener globalRoomListener;

    /**
     * Default constructor for the FirebaseManager class.
     *
     * @param context The application context.
     */
    public GlobalRoomManager(Context context) {
        super(context);
    }

    public static void setGlobalRoomName(String name) {
        Log.i(TAG, "Set global room name: " + name);
        globalRoomName = name;
    }

    @Override
    public boolean joinRoom(final RoomData roomData, final String uid, final boolean isPairing,