// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class ContactsContract {
//     public static final String TABLE_NAME = "contacts";
// 
//     public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build();
//     public static final int ALL_URI_CODE = 2;
//     public static final int URI_CODE = 3;
// 
//     public static class ContactEntry {
//         public static final String ID = BaseColumns._ID;
//         public static final String UUID = "uuid";
//         public static final String NAME = "name";
//     }
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class ContactEntry {
//     public static final String ID = BaseColumns._ID;
//     public static final String UUID = "uuid";
//     public static final String NAME = "name";
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class MessagesContract {
//     public static final String TABLE_NAME = "messages";
// 
//     public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build();
//     public static final int ALL_URI_CODE = 0;
//     public static final int URI_CODE = 1;
// 
//     public static class MessageEntry {
//         public static final String ID = BaseColumns._ID;
//         public static final String SENDER_UUID = "sender_uuid";
//         public static final String SENDER_NAME = "sender_name";
//         public static final String MESSAGE = "message";
//         public static final String RECEIVED_TIME = "received_time";
//     }
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class MessageEntry {
//     public static final String ID = BaseColumns._ID;
//     public static final String SENDER_UUID = "sender_uuid";
//     public static final String SENDER_NAME = "sender_name";
//     public static final String MESSAGE = "message";
//     public static final String RECEIVED_TIME = "received_time";
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java
// public interface QueryContactsUuidsCallback {
// 
//     void onComplete(@NonNull final Set<String> uuids);
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Contact.java
// public final class Contact {
// 
//     @NonNull
//     private final String name;
// 
//     @NonNull
//     private final String uuid;
// 
//     public Contact(@NonNull final String name, @NonNull final String uuid) {
//         this.name = name;
//         this.uuid = uuid;
//     }
// 
//     @NonNull
//     public String getName() {
//         return name;
//     }
// 
//     @NonNull
//     public String getUuid() {
//         return uuid;
//     }
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Message.java
// public final class Message {
// 
//     @NonNull
//     private final String senderUuid;
// 
//     @NonNull
//     private final String messageText;
// 
//     private final long receivedTime;
// 
//     public Message(@NonNull final String senderUuid,
//                    @NonNull final String messageText,
//                    final long receivedTime) {
//         this.senderUuid = senderUuid;
//         this.messageText = messageText;
//         this.receivedTime = receivedTime;
//     }
// 
//     @NonNull
//     public String getSenderUuid() {
//         return senderUuid;
//     }
// 
//     @NonNull
//     public String getMessageText() {
//         return messageText;
//     }
// 
//     public long getReceivedTime() {
//         return receivedTime;
//     }
// }


import org.onepf.pushchat.model.db.Message;
import java.util.HashSet;
import java.util.Set;
import android.content.AsyncQueryHandler;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.NonNull;
import org.onepf.pushchat.db.ContentDescriptor.ContactsContract;
import org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry;
import org.onepf.pushchat.db.ContentDescriptor.MessagesContract;
import org.onepf.pushchat.db.ContentDescriptor.MessagesContract.MessageEntry;
import org.onepf.pushchat.db.DatabaseHelper.ContactsUuidsAsyncQueryHandler.QueryContactsUuidsCallback;
import org.onepf.pushchat.model.db.Contact;

    public static DatabaseHelper getInstance(@NonNull final Context context) {
        if (instance == null) {
            synchronized (DatabaseHelper.class) {
                if (instance == null) {
                    instance = new DatabaseHelper(context);
                }
            }
        }

        return instance;
    }

    @Override
    public void onCreate(@NonNull final SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL(SQL_CREATE_CONTACTS_TABLE);
        sqLiteDatabase.execSQL(SQL_CREATE_MESSAGES_TABLE);
    }

    @Override
    public void onUpgrade(@NonNull final SQLiteDatabase sqLiteDatabase,
                          final int oldVersion,
                          final int newVersion) {
        if (oldVersion < newVersion) {
            sqLiteDatabase.execSQL(SQL_DELETE_MESSAGES_TABLE);
            sqLiteDatabase.execSQL(SQL_DELETE_CONTACTS_TABLE);
            onCreate(sqLiteDatabase);
        }
    }

// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class ContactsContract {
//     public static final String TABLE_NAME = "contacts";
// 
//     public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build();
//     public static final int ALL_URI_CODE = 2;
//     public static final int URI_CODE = 3;
// 
//     public static class ContactEntry {
//         public static final String ID = BaseColumns._ID;
//         public static final String UUID = "uuid";
//         public static final String NAME = "name";
//     }
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class ContactEntry {
//     public static final String ID = BaseColumns._ID;
//     public static final String UUID = "uuid";
//     public static final String NAME = "name";
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class MessagesContract {
//     public static final String TABLE_NAME = "messages";
// 
//     public static final Uri TABLE_URI = CONTENT_BASE_URI.buildUpon().appendPath(TABLE_NAME).build();
//     public static final int ALL_URI_CODE = 0;
//     public static final int URI_CODE = 1;
// 
//     public static class MessageEntry {
//         public static final String ID = BaseColumns._ID;
//         public static final String SENDER_UUID = "sender_uuid";
//         public static final String SENDER_NAME = "sender_name";
//         public static final String MESSAGE = "message";
//         public static final String RECEIVED_TIME = "received_time";
//     }
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/ContentDescriptor.java
// public static class MessageEntry {
//     public static final String ID = BaseColumns._ID;
//     public static final String SENDER_UUID = "sender_uuid";
//     public static final String SENDER_NAME = "sender_name";
//     public static final String MESSAGE = "message";
//     public static final String RECEIVED_TIME = "received_time";
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java
// public interface QueryContactsUuidsCallback {
// 
//     void onComplete(@NonNull final Set<String> uuids);
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Contact.java
// public final class Contact {
// 
//     @NonNull
//     private final String name;
// 
//     @NonNull
//     private final String uuid;
// 
//     public Contact(@NonNull final String name, @NonNull final String uuid) {
//         this.name = name;
//         this.uuid = uuid;
//     }
// 
//     @NonNull
//     public String getName() {
//         return name;
//     }
// 
//     @NonNull
//     public String getUuid() {
//         return uuid;
//     }
// }
// 
// Path: samples/pushchat/src/main/java/org/onepf/pushchat/model/db/Message.java
// public final class Message {
// 
//     @NonNull
//     private final String senderUuid;
// 
//     @NonNull
//     private final String messageText;
// 
//     private final long receivedTime;
// 
//     public Message(@NonNull final String senderUuid,
//                    @NonNull final String messageText,
//                    final long receivedTime) {
//         this.senderUuid = senderUuid;
//         this.messageText = messageText;
//         this.receivedTime = receivedTime;
//     }
// 
//     @NonNull
//     public String getSenderUuid() {
//         return senderUuid;
//     }
// 
//     @NonNull
//     public String getMessageText() {
//         return messageText;
//     }
// 
//     public long getReceivedTime() {
//         return receivedTime;
//     }
// }


// Path: samples/pushchat/src/main/java/org/onepf/pushchat/db/DatabaseHelper.java
import org.onepf.pushchat.model.db.Message;
import java.util.HashSet;
import java.util.Set;
import android.content.AsyncQueryHandler;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.NonNull;
import org.onepf.pushchat.db.ContentDescriptor.ContactsContract;
import org.onepf.pushchat.db.ContentDescriptor.ContactsContract.ContactEntry;
import org.onepf.pushchat.db.ContentDescriptor.MessagesContract;
import org.onepf.pushchat.db.ContentDescriptor.MessagesContract.MessageEntry;
import org.onepf.pushchat.db.DatabaseHelper.ContactsUuidsAsyncQueryHandler.QueryContactsUuidsCallback;
import org.onepf.pushchat.model.db.Contact;


    public static DatabaseHelper getInstance(@NonNull final Context context) {
        if (instance == null) {
            synchronized (DatabaseHelper.class) {
                if (instance == null) {
                    instance = new DatabaseHelper(context);
                }
            }
        }

        return instance;
    }

    @Override
    public void onCreate(@NonNull final SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL(SQL_CREATE_CONTACTS_TABLE);
        sqLiteDatabase.execSQL(SQL_CREATE_MESSAGES_TABLE);
    }

    @Override
    public void onUpgrade(@NonNull final SQLiteDatabase sqLiteDatabase,
                          final int oldVersion,
                          final int newVersion) {
        if (oldVersion < newVersion) {
            sqLiteDatabase.execSQL(SQL_DELETE_MESSAGES_TABLE);
            sqLiteDatabase.execSQL(SQL_DELETE_CONTACTS_TABLE);
            onCreate(sqLiteDatabase);
        }
    }

    public void addMessage(@NonNull final Message message) {