package eu.mhsl.minenet.minigames.instance.game.stateless.config.restriction;

import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;

import java.util.ArrayList;
import java.util.List;

public class RestrictionHandler {
    private List<IRestriction> restrictions = new ArrayList<>();

    public RestrictionHandler(IRestriction... restrictions) {
        this.restrictions = List.of(restrictions);
    }

    public RestrictionHandler() {

    }

    public RestrictionHandler addRestriction(IRestriction IRestriction) {
        this.restrictions.add(IRestriction);
        return this;
    }

    public List<IRestriction> getRestrictions() {
        return restrictions;
    }

    public boolean canPlay(RestrictionData data) {
        if(restrictions.size() < 1) return true;
        return this.restrictions.stream()
                .noneMatch(iRestriction -> iRestriction.calculate(data).type().equals(Restriction.Type.FAIL));
    }

    public List<TranslatedComponent> getWarnings(RestrictionData data) {
        List<TranslatedComponent> warnings = new ArrayList<>();
        for (IRestriction r : this.restrictions) {
            Restriction calculated = r.calculate(data);
            if(!calculated.type().equals(Restriction.Type.WARN)) continue;

            warnings.add(calculated.warnMessage());
        }
        return warnings;
    }
}
