package com.atlassian.stash.internal.notification.rest;

import com.atlassian.stash.internal.notification.usersettings.SendMode;
import com.atlassian.stash.internal.notification.usersettings.UserNotificationSettings;
import com.atlassian.bitbucket.rest.annotation.JsonSurrogate;
import com.atlassian.bitbucket.rest.RestMapEntity;
import com.google.common.base.Function;
import org.codehaus.jackson.map.annotate.JsonSerialize;

import javax.annotation.Nullable;

@JsonSurrogate(UserNotificationSettings.class)
@JsonSerialize
public class RestUserNotificationSettings extends RestMapEntity {

    private static final String SEND_MODE = "sendMode";

    public static final Function<UserNotificationSettings, RestUserNotificationSettings> REST_TRANSFORM = new Function<UserNotificationSettings, RestUserNotificationSettings>() {

        @Override
        public RestUserNotificationSettings apply(UserNotificationSettings input) {
            return new RestUserNotificationSettings(input);
        }
    };

    public RestUserNotificationSettings(UserNotificationSettings input) {
        putIfNotNull(SEND_MODE, input.getSendMode());
    }

    @SuppressWarnings("unused") //Required for Jersey
    public RestUserNotificationSettings() {
    }

    @Nullable
    public SendMode getSendMode() {
        return getEnumProperty(SEND_MODE, SendMode.class);
    }
}
