package com.os.operando.garum;

import android.content.Context;

import com.os.operando.garum.models.PrefModel;
import com.os.operando.garum.serializers.TypeSerializer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Configuration {

    private Context context;
    private List<Class<? extends PrefModel>> modelClasses;
    private List<Class<? extends TypeSerializer>> typeSerializers;
    private int cacheSize;

    private Configuration(Context context) {
        this.context = context;
    }

    public Context getContext() {
        return context;
    }

    public List<Class<? extends PrefModel>> getModelClasses() {
        return modelClasses;
    }

    public List<Class<? extends TypeSerializer>> getTypeSerializers() {
        return typeSerializers;
    }

    public int getCacheSize() {
        return cacheSize;
    }

    public boolean isValid() {
        return modelClasses != null && modelClasses.size() > 0;
    }

    public static class Builder {

        private static final int DEFAULT_CACHE_SIZE = 1024;
        private Context context;
        private Integer cacheSize;
        private List<Class<? extends PrefModel>> modelClasses = new ArrayList<>();
        private List<Class<? extends TypeSerializer>> typeSerializers;

        public Builder(Context context) {
            this.context = context.getApplicationContext();
            cacheSize = DEFAULT_CACHE_SIZE;
        }

        public Builder setCacheSize(int cacheSize) {
            this.cacheSize = cacheSize;
            return this;
        }

        public Builder addModelClass(Class<? extends PrefModel> modelClass) {
            modelClasses.add(modelClass);
            return this;
        }

        public Builder addModelClasses(Class<? extends PrefModel>... modelClasses) {
            this.modelClasses.addAll(Arrays.asList(modelClasses));
            return this;
        }

        public Builder setModelClasses(Class<? extends PrefModel>... modelClasses) {
            this.modelClasses = Arrays.asList(modelClasses);
            return this;
        }

        public Builder addTypeSerializer(Class<? extends TypeSerializer> typeSerializer) {
            if (typeSerializers == null) {
                typeSerializers = new ArrayList<>();
            }
            typeSerializers.add(typeSerializer);
            return this;
        }

        public Builder addTypeSerializers(Class<? extends TypeSerializer>... typeSerializers) {
            if (this.typeSerializers == null) {
                this.typeSerializers = new ArrayList<>();
            }
            this.typeSerializers.addAll(Arrays.asList(typeSerializers));
            return this;
        }

        public Builder setTypeSerializers(Class<? extends TypeSerializer>... typeSerializers) {
            this.typeSerializers = Arrays.asList(typeSerializers);
            return this;
        }

        public Configuration create() {
            Configuration configuration = new Configuration(context);
            configuration.cacheSize = cacheSize;
            // todo Get model classes from meta-data
            if (modelClasses != null) {
                configuration.modelClasses = modelClasses;
            }
            // todo Get serializer classes from meta-data
            if (typeSerializers != null) {
                configuration.typeSerializers = typeSerializers;
            }
            return configuration;
        }
    }
}

@@ -428,35 +428,8 @@
 ers;
-%0A    private int cacheSize;
 %0A%0A  
@@ -790,73 +790,8 @@
  %7D%0A%0A
-    public int getCacheSize() %7B%0A        return cacheSize;%0A    %7D%0A%0A
     
@@ -943,118 +943,23 @@
 ate 
-static final int DEFAULT_CACHE_SIZE = 1024;%0A        private Context context;%0A        private Integer cacheSize
+Context context
 ;%0A  
@@ -1217,181 +1217,8 @@
 ();%0A
-            cacheSize = DEFAULT_CACHE_SIZE;%0A        %7D%0A%0A        public Builder setCacheSize(int cacheSize) %7B%0A            this.cacheSize = cacheSize;%0A            return this;%0A
     
@@ -2674,57 +2674,8 @@
 t);%0A
-            configuration.cacheSize = cacheSize;%0A
     

Delete config cache size