// Path: app/src/main/java/com/w9jds/marketbot/classes/models/Type.java
// public final class Type extends MarketItemBase implements Parcelable {
// 
//     private String href;
//     private String icon;
//     private String marketGroup;
//     private long groupId;
// 
//     public String getHref() {
//         return href;
//     }
// 
//     public String getIcon() {
//         return icon;
//     }
// 
//     public long getGroupId() {
//         return groupId;
//     }
// 
//     public String getMarketGroup() {
//         return marketGroup;
//     }
// 
//     public static class Builder {
// 
//         private long id;
//         private String name;
//         private String href;
//         private String icon;
//         private String marketGroup;
//         private long groupId;
// 
//         public Builder setId(long id) {
//             this.id = id;
//             return this;
//         }
// 
//         public Builder setName(String name) {
//             this.name = name;
//             return this;
//         }
// 
//         public Builder setHref(String href) {
//             this.href = href;
//             return this;
//         }
// 
//         public Builder setIcon(String icon) {
//             this.icon = icon;
//             return this;
//         }
// 
//         public Builder setMarketGroup(String marketGroup) {
//             this.marketGroup = marketGroup;
//             return this;
//         }
// 
//         public Builder setGroupId(long groupId) {
//             this.groupId = groupId;
//             return this;
//         }
// 
//         public Type build() {
//             Type type = new Type();
//             type.id = this.id;
//             type.name = this.name;
//             type.href = this.href;
//             type.icon = this.icon;
//             type.marketGroup = this.marketGroup;
//             type.groupId = this.groupId;
// 
//             return type;
//         }
// 
// 
//     }
// 
//     @Override
//     public int describeContents() {
//         return 0;
//     }
// 
//     @Override
//     public void writeToParcel(Parcel dest, int flags) {
//         dest.writeString(this.href);
//         dest.writeString(this.icon);
//         dest.writeString(this.marketGroup);
//         dest.writeString(this.name);
//         dest.writeLong(this.id);
//         dest.writeLong(this.groupId);
//     }
// 
//     public Type() {
// 
//     }
// 
//     protected Type(Parcel in) {
//         this.href = in.readString();
//         this.icon = in.readString();
//         this.marketGroup = in.readString();
//         this.name = in.readString();
//         this.id = in.readLong();
//         this.groupId = in.readLong();
//     }
// 
//     public static final Parcelable.Creator<Type> CREATOR = new Parcelable.Creator<Type>() {
//         @Override
//         public Type createFromParcel(Parcel source) {
//             return new Type(source);
//         }
// 
//         @Override
//         public Type[] newArray(int size) {
//             return new Type[size];
//         }
//     };
// }
// 
// Path: app/src/main/java/com/w9jds/marketbot/data/MarketDatabase.java
// @Database(name = MarketDatabase.NAME, version = MarketDatabase.VERSION)
// public class MarketDatabase {
// 
//     public static final String NAME = "MarketBotDb";
//     public static final int VERSION = 3;
// 
// 
//     public interface TransactionListener {
//         void onTransactionProgressUpdate(int progress, int max);
//     }
// }


import com.raizlabs.android.dbflow.annotation.Column;
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
import com.raizlabs.android.dbflow.annotation.Table;
import com.raizlabs.android.dbflow.runtime.TransactionManager;
import com.raizlabs.android.dbflow.runtime.transaction.process.ProcessModelInfo;
import com.raizlabs.android.dbflow.runtime.transaction.process.ProcessModelTransaction;
import com.raizlabs.android.dbflow.runtime.transaction.process.SaveModelTransaction;
import com.raizlabs.android.dbflow.sql.language.OrderBy;
import com.raizlabs.android.dbflow.sql.language.Select;
import com.raizlabs.android.dbflow.structure.BaseModel;
import com.w9jds.marketbot.classes.models.Type;
import com.w9jds.marketbot.data.MarketDatabase;
import org.devfleet.crest.model.CrestMarketType;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import rx.subjects.BehaviorSubject;
    public static void addNewMarketTypes(List<CrestMarketType> types, BehaviorSubject<Map.Entry<Integer, Integer>> subject) {
        int size = types.size();
        List<MarketTypeEntry> entries = new ArrayList<>(size);
        for (int i = 0; i < size; i++) {
            CrestMarketType type = types.get(i);

            MarketTypeEntry entry = new MarketTypeEntry();
            entry.id = type.getTypeId();
            entry.groupId = type.getGroupId();
            entry.href = type.getTypeHref();
            entry.icon = type.getTypeIcon();
            entry.name = type.getTypeName();
            entries.add(entry);
        }

        TransactionManager manager = TransactionManager.getInstance();
        ProcessModelTransaction transaction = new SaveModelTransaction<>(ProcessModelInfo.withModels(entries));

        transaction.setChangeListener((current, maxProgress, modifiedModel) -> {
            if (current % 25 == 0 || current == maxProgress) {
                subject.onNext(new AbstractMap.SimpleEntry<>((int) current, (int) maxProgress));
            }
        });

        manager.addTransaction(transaction);
    }

    private static Type buildMarketType(MarketTypeEntry entry) {
        return new Type.Builder()
            .setName(entry.name)
// Path: app/src/main/java/com/w9jds/marketbot/classes/models/Type.java
// public final class Type extends MarketItemBase implements Parcelable {
// 
//     private String href;
//     private String icon;
//     private String marketGroup;
//     private long groupId;
// 
//     public String getHref() {
//         return href;
//     }
// 
//     public String getIcon() {
//         return icon;
//     }
// 
//     public long getGroupId() {
//         return groupId;
//     }
// 
//     public String getMarketGroup() {
//         return marketGroup;
//     }
// 
//     public static class Builder {
// 
//         private long id;
//         private String name;
//         private String href;
//         private String icon;
//         private String marketGroup;
//         private long groupId;
// 
//         public Builder setId(long id) {
//             this.id = id;
//             return this;
//         }
// 
//         public Builder setName(String name) {
//             this.name = name;
//             return this;
//         }
// 
//         public Builder setHref(String href) {
//             this.href = href;
//             return this;
//         }
// 
//         public Builder setIcon(String icon) {
//             this.icon = icon;
//             return this;
//         }
// 
//         public Builder setMarketGroup(String marketGroup) {
//             this.marketGroup = marketGroup;
//             return this;
//         }
// 
//         public Builder setGroupId(long groupId) {
//             this.groupId = groupId;
//             return this;
//         }
// 
//         public Type build() {
//             Type type = new Type();
//             type.id = this.id;
//             type.name = this.name;
//             type.href = this.href;
//             type.icon = this.icon;
//             type.marketGroup = this.marketGroup;
//             type.groupId = this.groupId;
// 
//             return type;
//         }
// 
// 
//     }
// 
//     @Override
//     public int describeContents() {
//         return 0;
//     }
// 
//     @Override
//     public void writeToParcel(Parcel dest, int flags) {
//         dest.writeString(this.href);
//         dest.writeString(this.icon);
//         dest.writeString(this.marketGroup);
//         dest.writeString(this.name);
//         dest.writeLong(this.id);
//         dest.writeLong(this.groupId);
//     }
// 
//     public Type() {
// 
//     }
// 
//     protected Type(Parcel in) {
//         this.href = in.readString();
//         this.icon = in.readString();
//         this.marketGroup = in.readString();
//         this.name = in.readString();
//         this.id = in.readLong();
//         this.groupId = in.readLong();
//     }
// 
//     public static final Parcelable.Creator<Type> CREATOR = new Parcelable.Creator<Type>() {
//         @Override
//         public Type createFromParcel(Parcel source) {
//             return new Type(source);
//         }
// 
//         @Override
//         public Type[] newArray(int size) {
//             return new Type[size];
//         }
//     };
// }
// 
// Path: app/src/main/java/com/w9jds/marketbot/data/MarketDatabase.java
// @Database(name = MarketDatabase.NAME, version = MarketDatabase.VERSION)
// public class MarketDatabase {
// 
//     public static final String NAME = "MarketBotDb";
//     public static final int VERSION = 3;
// 
// 
//     public interface TransactionListener {
//         void onTransactionProgressUpdate(int progress, int max);
//     }
// }


// Path: app/src/main/java/com/w9jds/marketbot/data/storage/MarketTypeEntry.java
import com.raizlabs.android.dbflow.annotation.Column;
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
import com.raizlabs.android.dbflow.annotation.Table;
import com.raizlabs.android.dbflow.runtime.TransactionManager;
import com.raizlabs.android.dbflow.runtime.transaction.process.ProcessModelInfo;
import com.raizlabs.android.dbflow.runtime.transaction.process.ProcessModelTransaction;
import com.raizlabs.android.dbflow.runtime.transaction.process.SaveModelTransaction;
import com.raizlabs.android.dbflow.sql.language.OrderBy;
import com.raizlabs.android.dbflow.sql.language.Select;
import com.raizlabs.android.dbflow.structure.BaseModel;
import com.w9jds.marketbot.classes.models.Type;
import com.w9jds.marketbot.data.MarketDatabase;
import org.devfleet.crest.model.CrestMarketType;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import rx.subjects.BehaviorSubject;

    public static void addNewMarketTypes(List<CrestMarketType> types, BehaviorSubject<Map.Entry<Integer, Integer>> subject) {
        int size = types.size();
        List<MarketTypeEntry> entries = new ArrayList<>(size);
        for (int i = 0; i < size; i++) {
            CrestMarketType type = types.get(i);

            MarketTypeEntry entry = new MarketTypeEntry();
            entry.id = type.getTypeId();
            entry.groupId = type.getGroupId();
            entry.href = type.getTypeHref();
            entry.icon = type.getTypeIcon();
            entry.name = type.getTypeName();
            entries.add(entry);
        }

        TransactionManager manager = TransactionManager.getInstance();
        ProcessModelTransaction transaction = new SaveModelTransaction<>(ProcessModelInfo.withModels(entries));

        transaction.setChangeListener((current, maxProgress, modifiedModel) -> {
            if (current % 25 == 0 || current == maxProgress) {
                subject.onNext(new AbstractMap.SimpleEntry<>((int) current, (int) maxProgress));
            }
        });

        manager.addTransaction(transaction);
    }

    private static Type buildMarketType(MarketTypeEntry entry) {
        return new Type.Builder()
            .setName(entry.name)
            .setGroupId(entry.groupId)