package com.atlassian.bitbucket.rest.license;

import com.atlassian.bitbucket.i18n.KeyedMessage;
import com.atlassian.bitbucket.rest.RestMapEntity;

public class RestLicenseStatus extends RestMapEntity {

    private static final String CURRENT_NUMBER_OF_USERS = "currentNumberOfUsers";
    private static final String OVER_LIMIT_MESSAGE = "overLimitMessage";
    private static final String SERVER_ID = "serverId";
    private static final String VALIDITY_MESSAGE = "validityMessage";

    public RestLicenseStatus(String serverId, int currentNumberOfUsers,
                             KeyedMessage overLimitMessage, KeyedMessage validityMessage) {
        put(CURRENT_NUMBER_OF_USERS, currentNumberOfUsers);
        put(SERVER_ID, serverId);
        putMessage(OVER_LIMIT_MESSAGE, overLimitMessage);
        putMessage(VALIDITY_MESSAGE, validityMessage);
    }

    private void putMessage(String key, KeyedMessage value) {
        if (value != null) {
            put(key, value.getLocalisedMessage());
        }
    }
}
