package com.atlassian.stash.internal.web.soy.functions.pagedata;

import com.atlassian.soy.renderer.SoyServerFunction;
import com.atlassian.stash.internal.plugin.web.fragments.ClientPageDataHandler;
import com.google.common.collect.ImmutableSet;

import java.util.Set;

/**
 * Provides the includePageData() Soy function, which will generate a &lt;script&gt; tag that loads all
 * data previously required with requirePageData() into the _PageDataPlugin object.
 */
public class IncludePageDataFunction implements SoyServerFunction<String> {


    private final ClientPageDataHandler clientPageDataHandler;

    public IncludePageDataFunction(ClientPageDataHandler clientPageDataHandler) {
        this.clientPageDataHandler = clientPageDataHandler;
    }

    @Override
    public String getName() {
        return "includePageData";
    }

    @Override
    public String apply(Object... args) {
        return clientPageDataHandler.toPageDataScript();
    }

    @Override
    public Set<Integer> validArgSizes() {
        return ImmutableSet.of(0);
    }
}