package com.messagebird.objects;

import com.messagebird.exceptions.GeneralException;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;

public class PurchasedNumbersFilter implements Serializable {
    private int limit = 10;
    private int offset = 0;
    private EnumSet<PhoneNumberFeature> features = EnumSet.noneOf(PhoneNumberFeature.class);
    private ArrayList<String> tags = new ArrayList<>();
    private String number;
    private String region;
    private String locality;
    private PhoneNumberType type;

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public int getOffset() {
        return offset;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }

    public EnumSet<PhoneNumberFeature> getFeatures() {
        return features;
    }

    public void addFeature(PhoneNumberFeature feature) {
        this.features.add(feature);
    }

    public void removeFeature(PhoneNumberFeature feature) {
        this.features.remove(feature);
    }

    public ArrayList<String> getTags() {
        return tags;
    }

    public void addTag(String tag) {
        this.tags.add(tag);
    }

    public void clearTags() {
        this.tags.clear();
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getRegion() {
        return region;
    }

    public void setRegion(String region) {
        this.region = region;
    }

    public String getLocality() {
        return locality;
    }

    public void setLocality(String locality) {
        this.locality = locality;
    }

    public PhoneNumberType getType() {
        return type;
    }

    public void setType(PhoneNumberType type) {
        this.type = type;
    }

    public HashMap<String, Object> toHashMap() throws GeneralException {
        final HashMap<String, Object> map = new HashMap<String, Object>();
        for (Field f: getClass().getDeclaredFields()) {
            if (f.canAccess(this)) {
                try {
                    Object value = f.get(this);
                    String key = f.getName();
                    if (value != null) {
                        map.put(key, value);
                    }
                } catch (IllegalAccessException exception) {
                    throw new GeneralException("Error converting to HashMap.");
                }
            }
        }
        return map;
    }

    @Override
    public String toString() {
        return "PurchasedNumbersFilter{" +
                "limit=" + limit +
                ", offset=" + offset +
                ", features=" + features +
                ", tags=" + tags +
                ", number='" + number + '\'' +
                ", region='" + region + '\'' +
                ", locality='" + locality + '\'' +
                ", type=" + type +
                '}';
    }
}

@@ -1001,32 +1001,35 @@
 umberFeature
+...
  feature
 ) %7B%0A        
@@ -1008,36 +1008,94 @@
 ature... feature
+s
 ) %7B%0A
+        for (PhoneNumberFeature feature: features) %7B%0A    
         this.fea
@@ -1106,32 +1106,42 @@
 s.add(feature);%0A
+        %7D%0A
     %7D%0A%0A    publi
@@ -1179,24 +1179,27 @@
 rFeature
+...
  feature
 ) %7B%0A    
@@ -1190,20 +1190,78 @@
  feature
+s
 ) %7B%0A
+        for (PhoneNumberFeature feature: features) %7B%0A    
         
@@ -1287,24 +1287,34 @@
 e(feature);%0A
+        %7D%0A
     %7D%0A%0A    p
@@ -1406,20 +1406,24 @@
 g(String
+...
  tag
+s
 ) %7B%0A    
@@ -1430,27 +1430,265 @@
     
-this.tags.add(tag);
+for (String tag: tags) %7B%0A            if (!this.tags.contains(tag)) %7B%0A                this.tags.add(tag);%0A            %7D%0A        %7D%0A    %7D%0A%0A    public void removeTag(String... tags) %7B%0A        for (String tag: tags) %7B%0A            this.tags.remove(tag);%0A        %7D
 %0A   

Allow adding/removing multiple features/tags at a time