package com.atlassian.stash.internal.plugin;

import com.atlassian.plugin.module.ModuleFactory;
import com.atlassian.plugin.util.validation.ValidationPattern;
import com.atlassian.bitbucket.json.JsonRenderer;
import com.atlassian.bitbucket.scm.BaseWeightedModuleDescriptor;

import static com.atlassian.plugin.util.validation.ValidationPattern.test;

public class JsonRendererModuleDescriptor extends BaseWeightedModuleDescriptor<JsonRenderer> {

    public static final String XML_ELEMENT_NAME = "json-renderer";

    public JsonRendererModuleDescriptor(ModuleFactory moduleFactory) {
        super(moduleFactory, 1000);
    }

    @Override
    protected void provideValidationRules(ValidationPattern pattern) {
        super.provideValidationRules(pattern);
        pattern.rule(test("@class").withError("The json-renderer class is required"));
    }

    @Override
    public JsonRenderer getModule() {
        return moduleFactory.createModule(moduleClassName, this);
    }
}
