package ch.pizzalink.android.model;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import java.io.Serializable;
import java.util.ArrayList;

import ch.pizzalink.android.api.ApiConstants;
import ch.pizzalink.android.helper.SharedPrefsHelper;

/**
 * Created by cimenmus on 26/09/2017.
 */

public class CategoryModel implements Serializable{

    @Expose
    @SerializedName("category_id")
    private int id;

    @Expose
    @SerializedName("name")
    private String name;

    @Expose
    @SerializedName("children")
    private ArrayList<CategoryModel> subCategoryList;

    public void checkNull(){
        if(name == null)
            name = "";
    }

    public static void checkNull(ArrayList<CategoryModel> categoryList){
        for (CategoryModel categoryModel : categoryList){
            categoryModel.checkNull();
            if(categoryModel.getSubCategoryList() != null &&
                    categoryModel.getSubCategoryList().size() > 0){
                for(CategoryModel subCategoryModel : categoryModel.subCategoryList){
                    subCategoryModel.checkNull();
                }
            }
        }
    }

    public boolean isDescriptionVisible(){
        return !SharedPrefsHelper.readIgnoredCategoryIdList().contains(id);
    }

    public String getCategoryIdString(){
        return String.valueOf(id);
    }

    public boolean isProduct(){
        return id == ApiConstants.CATEGORY_ID_WUNSCHPIZZA || id == ApiConstants.CATEGORY_ID_EKSTRA_KEBAP;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public ArrayList<CategoryModel> getSubCategoryList() {
        return subCategoryList;
    }

    public void setSubCategoryList(ArrayList<CategoryModel> subCategoryList) {
        this.subCategoryList = subCategoryList;
    }
}
