// 名前空間
var CHAT_DB = {};


//ロカールDBからルーム一覧情報を取得
CHAT_DB.getRoomList = function(roomType, keyWord) {
    if (CHAT_UTIL.isIOS()) {
        return JSON.parse(iosRoomList);        
    } else if (CHAT_UTIL.isAndroid()) {
    	return JSON.parse(android.getRoomList(roomType, keyWord));
    }
};

var iosRoomList;
CHAT_DB.getIosRoomList = function(roomList) {
	iosRoomList = roomList;
    CHAT_DB.getRoomList(0);
};

CHAT_DB.callGetRoomList = function(roomType) {
    if (CHAT_UTIL.isIOS()) {
        webkit.messageHandlers.getRoomList.postMessage({roomType});
    } else if (CHAT_UTIL.isAndroid()) {
        //String形式をJsonに変更してReturn
    	return JSON.parse(android.getRoomList(roomType));
    }
}

//ロカールDBからログインしたユーザのデータを取得する。
CHAT_DB.getMyInfo = function(input) {
    if (CHAT_UTIL.isIOS()) {
        //TODO IOS処理追加必要
        
    } else if (CHAT_UTIL.isAndroid()) {
        //String形式をJsonに変更してReturn
    	return JSON.parse(android.getMyInfo());
    }
};

CHAT_DB.getMessages = function(roomId) {
    if (CHAT_UTIL.isIOS()) {
        //TODO IOS処理追加必要
    } else if (CHAT_UTIL.isAndroid()) {
        //String形式をJsonに変更してReturn
    	return JSON.parse(android.getMessageList(roomId));
    }
};

CHAT_DB.getFavoriteUsersNotInRoom = function() {
    if (CHAT_UTIL.isIOS()) {
        //TODO IOS処理追加必要
    } else if (CHAT_UTIL.isAndroid()) {
        //String形式をJsonに変更してReturn
    	return JSON.parse(android.getFavoriteUsersNotInRoom());
    }
};

CHAT_DB.getFavoriteUsers = function() {
    if (CHAT_UTIL.isIOS()) {
        //TODO IOS処理追加必要
    } else if (CHAT_UTIL.isAndroid()) {
        //String形式をJsonに変更してReturn
    	return JSON.parse(android.getFavoriteUsers());
    }
};

CHAT_DB.getFavoriteGroups = function() {
    if (CHAT_UTIL.isIOS()) {
        //TODO IOS処理追加必要
    } else if (CHAT_UTIL.isAndroid()) {
        //String形式をJsonに変更してReturn
    	return JSON.parse(android.getFavoriteGroups());
    }
};

CHAT_DB.getMyGroupUsers = function() {
    if (CHAT_UTIL.isIOS()) {
        //TODO IOS処理追加必要
    } else if (CHAT_UTIL.isAndroid()) {
        //String形式をJsonに変更してReturn
    	return JSON.parse(android.getMyGroupUsers());
    }
};

CHAT_DB.getGroupInfo = function(groupId) {
    if (CHAT_UTIL.isIOS()) {
        //TODO IOS処理追加必要
    } else if (CHAT_UTIL.isAndroid()) {
        //String形式をJsonに変更してReturn
    	return JSON.parse(android.getGroupInfo(groupId));
    }
};

CHAT_DB.loadSelectedUsers = function() {
    if (CHAT_UTIL.isIOS()) {
        //TODO IOS処理追加必要
    } else if (CHAT_UTIL.isAndroid()) {
        //String形式をJsonに変更してReturn
        console.log(JSON.parse(android.getSelectedUserList()));
    	return JSON.parse(android.getSelectedUserList());
    }
}

CHAT_DB.getNameCardData = function(shopMemberId) {
    if (CHAT_UTIL.isIOS()) {
        //TODO IOS処理追加必要
    } else if (CHAT_UTIL.isAndroid()) {
    	return JSON.parse(android.getNameCardData(shopMemberId));
    }
};

CHAT_DB.getMyGroupShopMemberByName = function(shopMemberName) {
    if (CHAT_UTIL.isIOS()) {
        //TODO IOS処理追加必要
    } else if (CHAT_UTIL.isAndroid()) {
        //String形式をJsonに変更してReturn
    	return JSON.parse(android.getMyGroupShopMemberByName(shopMemberName));
    }
};

CHAT_DB.getMyGroupShopMemberNotInRoomByName = function(shopMemberName) {
    if (CHAT_UTIL.isIOS()) {
        //TODO IOS処理追加必要
    } else if (CHAT_UTIL.isAndroid()) {
        //String形式をJsonに変更してReturn
    	return JSON.parse(android.getMyGroupShopMemberNotInRoomByName(shopMemberName));
    }
};

CHAT_DB.getAllGroupShopMemberByName = function(shopMemberName) {
    if (CHAT_UTIL.isIOS()) {
        //TODO IOS処理追加必要
    } else if (CHAT_UTIL.isAndroid()) {
        //String形式をJsonに変更してReturn
    	return JSON.parse(android.getAllGroupShopMemberByName(shopMemberName));
    }
};

CHAT_DB.getAllGroupShopMemberNotInRoomByName = function(shopMemberName) {
    if (CHAT_UTIL.isIOS()) {
        //TODO IOS処理追加必要
    } else if (CHAT_UTIL.isAndroid()) {
        //String形式をJsonに変更してReturn
    	return JSON.parse(android.getAllGroupShopMemberNotInRoomByName(shopMemberName));
    }
};

CHAT_DB.getGroupByName = function(groupName) {
    if (CHAT_UTIL.isIOS()) {
        //TODO IOS処理追加必要
    } else if (CHAT_UTIL.isAndroid()) {
        //String形式をJsonに変更してReturn
    	return JSON.parse(android.getGroupByName(groupName));
    }
};

CHAT_DB.getUsersInRoom = function(roomId) {
    if (CHAT_UTIL.isIOS()) {
        //TODO IOS処理追加必要
    } else if (CHAT_UTIL.isAndroid()) {
        //String形式をJsonに変更してReturn
    	return JSON.parse(android.getUsersInRoom(roomId));
    }
}

// アーカイブ一覧
var iosArchiveList;

CHAT_DB.callGetArchiveList = function() {
    if (CHAT_UTIL.isIOS()) {
        iosArchiveList = "";
        webkit.messageHandlers.getArchiveList.postMessage();
    } else if (CHAT_UTIL.isAndroid()) {
        CHAT_UI.refreshArchiveScreen();
    }
};

CHAT_DB.getIosArchiveList = function(archiveList) {
    iosArchiveList = archiveList;
    CHAT_UI.refreshArchiveScreen();
};

CHAT_DB.getArchiveList = function() {
    if (CHAT_UTIL.isIOS()) {
        return JSON.parse(iosArchiveList);
    } else if (CHAT_UTIL.isAndroid()) {
        // TODO
    }
};

CHAT_DB.updateArchiveList = function() {
    if (CHAT_UTIL.isIOS()) {
        webkit.messageHandlers.updateArchiveList.postMessage();
    } else if (CHAT_UTIL.isAndroid()) {
        // TODO
    }
};

// アーカイブ一覧検索
var iosSearchArchiveList;
var searchWord;

CHAT_DB.callGetArchiveByName = function(keyword) {
    if (CHAT_UTIL.isIOS()) {
        iosSearchArchiveList = "";
        searchWord = keyword;
        webkit.messageHandlers.getArchiveByName.postMessage({keyword});
    } else if (CHAT_UTIL.isAndroid()) {
        ARCHIVE_UI.refreshSearchScreen(keyword);
    }
};

CHAT_DB.getIosSearchArchiveList = function(archiveList) {
    iosSearchArchiveList = archiveList;
    ARCHIVE_UI.refreshSearchScreen(searchWord);
};

CHAT_DB.getArchiveByName = function(archiveName) {
    if (CHAT_UTIL.isIOS()) {
        return JSON.parse(iosSearchArchiveList);
    } else if (CHAT_UTIL.isAndroid()) {
        // TODO
    }
};

// アーカイブ詳細
var iosArchiveDetail;
CHAT_DB.getIosArchiveDetail = function(archiveDetail) {
    iosArchiveDetail = archiveDetail;
    CHAT_DB.callGetArchiveDetail(archiveDetail.archiveId);
};

CHAT_DB.callGetArchiveDetail = function(archiveId) {
    if (CHAT_UTIL.isIOS()) {
        iosArchiveDetail = "";
        webkit.messageHandlers.getArchiveDetail.postMessage({archiveId});
    } else if (CHAT_UTIL.isAndroid()) {
        CHAT_UI.refreshArchiveDetailScreen(archiveId);
    }
};

CHAT_DB.getArchiveDetail = function() {
    if (CHAT_UTIL.isIOS()) {
        return JSON.parse(iosArchiveDetail);
    } else if (CHAT_UTIL.isAndroid()) {
        // TODO
    }
};

CHAT_DB.updateArchiveDetail = function(archiveId) {
    if (CHAT_UTIL.isIOS()) {
        webkit.messageHandlers.updateArchiveDetail.postMessage({archiveId});
    } else if (CHAT_UTIL.isAndroid()) {
        // TODO
    }
};

CHAT_DB.searchMessages = function(keyword, userList) {
    if (CHAT_UTIL.isIOS()) {
        // TODO
    } else if (CHAT_UTIL.isAndroid()) {
        return JSON.parse(android.searchMessages(keyword, userList));
    }
};

CHAT_DB.getMyGroupUsersNotInRoom = function() {
    if (CHAT_UTIL.isIOS()) {
        //TODO IOS処理追加必要
    } else if (CHAT_UTIL.isAndroid()) {
        //String形式をJsonに変更してReturn
    	return JSON.parse(android.getMyGroupUsersNotInRoom());
    }
};