package com.atlassian.stash.sal.api.help;

import com.atlassian.bitbucket.help.HelpPathService;
import com.atlassian.sal.api.message.DefaultHelpPath;
import com.atlassian.sal.api.message.HelpPath;
import com.atlassian.sal.api.message.HelpPathResolver;

public class HelpPathResolverImpl implements HelpPathResolver {
    private final HelpPathService helpPathService;

    public HelpPathResolverImpl(HelpPathService helpPathService) {
        this.helpPathService = helpPathService;
    }

    @Override
    public HelpPath getHelpPath(String key) {
        String pageKey = helpPathService.getPageKey(key);
        String helpUrl = helpPathService.getPageUrl(key);
        if (helpUrl != null && pageKey != null) {
            String title = helpPathService.getPageTitle(key);
            String alt = helpPathService.getPageAlt(key);
            return new DefaultHelpPath(pageKey, helpUrl, title, alt, false);
        } else {
            return null;
        }
    }
}
