package dev.fyloz.trial.colorrecipesexplorer.web.response;

import dev.fyloz.trial.colorrecipesexplorer.model.*;
import dev.fyloz.trial.colorrecipesexplorer.model.MaterialType;
import dev.fyloz.trial.colorrecipesexplorer.model.dto.MaterialTypeEditorDto;
import dev.fyloz.trial.colorrecipesexplorer.model.Material;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.stream.Stream;

public enum ResponseDataType {
    MATERIAL("material", Material.class),
    MATERIALS("materials", ArrayList.class, MATERIAL),
    MATERIAL_ID("materialId", Long.class),
    MATERIAL_CODE("materialCode", String.class),
    MATERIALS_JSON("materialsJson", String.class),

    MATERIAL_TYPE("materialType", MaterialType.class),
    MATERIAL_TYPES("materialTypes", ArrayList.class, MATERIAL_TYPE),
    MATERIAL_TYPE_NAME("materialTypeName", String.class),
    MATERIAL_TYPE_DTO("materialTypeDto", MaterialTypeEditorDto.class),

    RECIPE("recipe", Recipe.class),
    RECIPES("recipes", ArrayList.class, RECIPE),
    RECIPE_ID("recipeId", Long.class),
    RECIPE_CODE("recipeCode", String.class),
    RECIPE_MAP("recipeMap", HashMap.class),
    RECIPE_JSON("recipeJson", String.class),

    RECIPE_STEP("recipeStep", RecipeStep.class),
    RECIPE_STEPS("recipeSteps", ArrayList.class, RECIPE_STEP),

    MIX("mix", Mix.class),
    MIXES("mixes", ArrayList.class, MIX),
    MIX_ID("mixId", Long.class),
    MIX_JSON("mixJson", String.class),

    MIX_TYPE("mixType", MixType.class),
    MIX_TYPES("mixTypes", ArrayList.class, MIX_TYPE),

    MIX_QUANTITY("mixQuantity", MixQuantity.class),
    MIX_QUANTITIES("mixQuantities", ArrayList.class, MIX_QUANTITY),

    COMPANY("company", Company.class),
    COMPANIES("companies", ArrayList.class, COMPANY),
    COMPANY_ID("companyId", Long.class),
    COMPANY_NAME("companyName", String.class),

    IMAGE("image", String.class),
    IMAGES("images", ArrayList.class, IMAGE),

    BLOCK_BUTTON("blockButton", boolean.class);

    private String dataTypeName;
    private Class dataType;
    private Class listDataType;

    ResponseDataType(String dataTypeName, Class dataType) {
        this(dataTypeName, dataType, null);
    }

    ResponseDataType(String dataTypeName, Class dataType, ResponseDataType listDataType) {
        this.dataTypeName = dataTypeName;
        this.dataType = dataType;

        if (listDataType != null) {
            this.listDataType = listDataType.getDataType();
        }
    }

    public String getDataTypeName() {
        return dataTypeName;
    }

    public Class getDataType() {
        return dataType;
    }

    public Class getListDataType() {
        return listDataType;
    }

    @Override
    public String toString() {
        return getDataTypeName();
    }

    public static ResponseDataType getModelDataTypeFromDataType(Class dataType) {
        return Stream.of(values()).filter(r -> r.getDataType().equals(dataType)).findFirst().orElse(null);
    }
}
