package com.tiedup.remake.v2.bondage.component;

import com.google.gson.JsonObject;

/**
 * Component: struggle resistance for data-driven items.
 *
 * JSON config: {@code "resistance": {"base": 150}}
 */
public class ResistanceComponent implements IItemComponent {

    private final int baseResistance;

    private ResistanceComponent(int baseResistance) {
        this.baseResistance = baseResistance;
    }

    public static IItemComponent fromJson(JsonObject config) {
        int base = 100;
        if (config != null && config.has("base")) {
            base = config.get("base").getAsInt();
        }
        base = Math.max(0, base);
        return new ResistanceComponent(base);
    }

    /**
     * Get the base resistance for this item.
     */
    public int getBaseResistance() {
        return baseResistance;
    }
}
