package ch.pizzalemon.android.model;

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

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

import ch.pizzalemon.android.helper.SharedPrefsHelper;

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

public class CategoryModel implements Serializable{

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

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

    @Expose
    @SerializedName("is_special")
    private boolean specialCategory;

    @Expose
    @SerializedName("is_default")
    private boolean isDefault;

    @Expose
    @SerializedName("product_id")
    private String specialProductId;

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

    public void checkNull(){
        if(name == null)
            name = "";
        if(specialProductId == null)
            specialProductId = "";
        if(subCategoryList == null)
            subCategoryList = new ArrayList<>();
    }

    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 String getId() {
        return id != null ? id : "";
    }

    public void setId(String 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;
    }

    public boolean isSpecialCategory() {
        return specialCategory;
    }

    public void setSpecialCategory(boolean specialCategory) {
        this.specialCategory = specialCategory;
    }

    public String getSpecialProductId() {
        if(specialProductId == null){
            specialProductId = "";
        }
        return specialProductId;
    }

    public void setSpecialProductId(String specialProductId) {
        this.specialProductId = specialProductId;
    }

    public boolean isDefault() {
        return isDefault;
    }
}
