package com.atlassian.stash.internal.comment.like.config;

import com.atlassian.bitbucket.server.ApplicationPropertiesService;

/**
 * Default implementation of {@link CommentLikeConfig} based on {@link ApplicationPropertiesService Stash application
 * properties}
 *
 * @since 3.5
 */
public class DefaultCommentLikeConfig implements CommentLikeConfig {

    public static final String PROP_PREFIX = "plugin.bitbucket-comment-likes.";

    public static final String PROP_MAX_RESOURCES = PROP_PREFIX + "max.resources";
    public static final String PROP_MAX_PAGE_SIZE = PROP_PREFIX + "max.page";

    private static final int DEFAULT_MAX_RESOURCES = 500;
    private static final int DEFAULT_MAX_PAGE_SIZE = 100;

    private final ApplicationPropertiesService applicationPropertiesService;

    public DefaultCommentLikeConfig(ApplicationPropertiesService applicationPropertiesService) {
        this.applicationPropertiesService = applicationPropertiesService;
    }

    @Override
    public int getMaxPageSize() {
        return applicationPropertiesService.getPluginProperty(PROP_MAX_PAGE_SIZE, DEFAULT_MAX_PAGE_SIZE);
    }

    @Override
    public int getMaxResources() {
        return applicationPropertiesService.getPluginProperty(PROP_MAX_RESOURCES, DEFAULT_MAX_RESOURCES);
    }
}
