// Path: library/src/main/java/com/thefinestartist/royal/listener/OnRoyalListener.java
// public abstract class OnRoyalListener {
//     public void onUpdated() {}
//     public void onDeleted() {}
// }
// 
// Path: library/src/main/java/io/realm/RoyalAccess.java
// public class RoyalAccess {
// 
//     public static Realm getRealm(@NonNull RealmObject object) {
//         return object.realm;
//     }
// 
//     public static Row getRow(@NonNull RealmObject object) {
//         return object.row;
//     }
// 
//     public static Table getTable(@NonNull RealmObject object) {
//         return object.row == null ? null : object.row.getTable();
//     }
// 
//     public static boolean isProxy(@NonNull RealmObject object) {
//         return object instanceof RealmObjectProxy;
//     }
// 
//     public static boolean hasPrimaryKey(@NonNull Realm realm, @NonNull RealmObject object) {
//         return realm.getTable(object.getClass()).hasPrimaryKey();
//     }
// 
//     public static Class<? extends RealmObject> getClass(@NonNull Realm realm, @NonNull Table table) {
//         List<Class<? extends RealmObject>> classes = realm.getConfiguration().getSchemaMediator().getModelClasses();
//         for (Class<? extends RealmObject> clazz : classes)
//             if (realm.getTable(clazz).getName().equals(table.getName()))
//                 return clazz;
// 
//         return null;
//     }
// 
//     public static RealmObject get(@NonNull Realm realm, @NonNull Table table, long rowIndex) {
//         if (rowIndex < 0)
//             return null;
// 
//         UncheckedRow row = table.getUncheckedRow(rowIndex);
//         RealmObject result = realm.getConfiguration().getSchemaMediator().newInstance(getClass(realm, table));
//         result.row = row;
//         result.realm = realm;
//         return result;
//     }
// 
//     // TODO: Free RealmObject from Realm
// 
// 
//     // TODO: Clone RealmObject without Realm information
//     // TODO: Problem #1 Serializing RealmObject has same speed of just committing it using Realm
// 
// }


import android.os.AsyncTask;
import android.support.annotation.NonNull;
import com.thefinestartist.royal.listener.OnRoyalListener;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import io.realm.RealmObject;
import io.realm.RoyalAccess;
import io.realm.exceptions.RealmException;
//
//        Set<Realm> realms = getRealms(objects);
//        new SaveTask(realm.getConfiguration(), realms, listener).execute(objects);
//
//        new SaveTask(realm.getConfiguration(), null, listener).execute(objects);
//    }

    private static Set<Realm> getRealms(RealmObject[] objects) {
        Set<Realm> realms = new HashSet<>();
        for (RealmObject object : objects)
            realms.add(RoyalAccess.getRealm(object));
        realms.remove(null);
        return realms;
    }

    private static void incrementReferenceCount(Set<Realm> realms) {
        for (Realm realm : realms) {
            Realm newRealm = Realm.getInstance(realm.getConfiguration());
        }
    }

    private static void decrementReferenceCount(Set<Realm> realms) {
        for (Realm realm : realms)
            realm.close();
    }

    static class SaveTask extends AsyncTask<RealmObject, Void, Void> {

        RealmConfiguration configuration;
        Set<Realm> realms;
// Path: library/src/main/java/com/thefinestartist/royal/listener/OnRoyalListener.java
// public abstract class OnRoyalListener {
//     public void onUpdated() {}
//     public void onDeleted() {}
// }
// 
// Path: library/src/main/java/io/realm/RoyalAccess.java
// public class RoyalAccess {
// 
//     public static Realm getRealm(@NonNull RealmObject object) {
//         return object.realm;
//     }
// 
//     public static Row getRow(@NonNull RealmObject object) {
//         return object.row;
//     }
// 
//     public static Table getTable(@NonNull RealmObject object) {
//         return object.row == null ? null : object.row.getTable();
//     }
// 
//     public static boolean isProxy(@NonNull RealmObject object) {
//         return object instanceof RealmObjectProxy;
//     }
// 
//     public static boolean hasPrimaryKey(@NonNull Realm realm, @NonNull RealmObject object) {
//         return realm.getTable(object.getClass()).hasPrimaryKey();
//     }
// 
//     public static Class<? extends RealmObject> getClass(@NonNull Realm realm, @NonNull Table table) {
//         List<Class<? extends RealmObject>> classes = realm.getConfiguration().getSchemaMediator().getModelClasses();
//         for (Class<? extends RealmObject> clazz : classes)
//             if (realm.getTable(clazz).getName().equals(table.getName()))
//                 return clazz;
// 
//         return null;
//     }
// 
//     public static RealmObject get(@NonNull Realm realm, @NonNull Table table, long rowIndex) {
//         if (rowIndex < 0)
//             return null;
// 
//         UncheckedRow row = table.getUncheckedRow(rowIndex);
//         RealmObject result = realm.getConfiguration().getSchemaMediator().newInstance(getClass(realm, table));
//         result.row = row;
//         result.realm = realm;
//         return result;
//     }
// 
//     // TODO: Free RealmObject from Realm
// 
// 
//     // TODO: Clone RealmObject without Realm information
//     // TODO: Problem #1 Serializing RealmObject has same speed of just committing it using Realm
// 
// }


// Path: library/src/main/java/com/thefinestartist/royal/RoyalTransaction.java
import android.os.AsyncTask;
import android.support.annotation.NonNull;
import com.thefinestartist.royal.listener.OnRoyalListener;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import io.realm.RealmObject;
import io.realm.RoyalAccess;
import io.realm.exceptions.RealmException;

//
//        Set<Realm> realms = getRealms(objects);
//        new SaveTask(realm.getConfiguration(), realms, listener).execute(objects);
//
//        new SaveTask(realm.getConfiguration(), null, listener).execute(objects);
//    }

    private static Set<Realm> getRealms(RealmObject[] objects) {
        Set<Realm> realms = new HashSet<>();
        for (RealmObject object : objects)
            realms.add(RoyalAccess.getRealm(object));
        realms.remove(null);
        return realms;
    }

    private static void incrementReferenceCount(Set<Realm> realms) {
        for (Realm realm : realms) {
            Realm newRealm = Realm.getInstance(realm.getConfiguration());
        }
    }

    private static void decrementReferenceCount(Set<Realm> realms) {
        for (Realm realm : realms)
            realm.close();
    }

    static class SaveTask extends AsyncTask<RealmObject, Void, Void> {

        RealmConfiguration configuration;
        Set<Realm> realms;
        OnRoyalListener listener;