package com.atlassian.bitbucket.rest.property;

import com.atlassian.bitbucket.property.PropertySupport;
import com.atlassian.bitbucket.rest.RestMapEntity;

import java.util.Map;

/**
 * REST entity with {@link PropertySupport property support}.
 */
public abstract class RestPropertySupport extends RestMapEntity {

    public static final String PROPERTIES = "properties";

    //Required for Jersey
    protected RestPropertySupport() {
    }

    protected RestPropertySupport(Map<String, Object> properties) {
        putProperties(properties);
    }

    @SuppressWarnings("unchecked")
    public Map<String, Object> getProperties() {
       Object value = get(PROPERTIES);
        if (value instanceof Map) {
            return (Map<String, Object>) value;
        }

        return null;
    }

    protected void putProperties(Map<String, Object> properties) {
        putIfNotEmpty(PROPERTIES, new RestPropertyMap(properties));
    }
}
