// Path: achievements-server/src/main/java/org/jetbrains/buildserver/achievements/AchievementEvents.java
// public enum AchievementEvents {
//   buildUnpinned,
//   buildTagged,
//   testBombed,
//   testDisarmed,
//   compilationBroken,
//   investigationDelegated,
//   investigationTaken,
//   issueMentioned,
//   changeAdded,
//   userAction // with 5 minutes resolution
// }
// 
// Path: achievements-server/src/main/java/org/jetbrains/buildserver/achievements/UserEvents.java
// public interface UserEvents {
//   void registerEvent(@NotNull String eventName);
// 
//   void registerEvent(@NotNull String eventName, @Nullable Object additionalData);
// 
//   long getLastEventTime(@NotNull String eventName);
// 
//   // most recent first
//   @NotNull
//   List<Long> getEventTimes(@NotNull String eventName);
// 
//   int getNumberOfEvents(@NotNull String eventName);
// 
//   float getEventsRate(@NotNull String eventName, int timeIntervalSeconds);
// }
// 
// Path: achievements-server/src/main/java/org/jetbrains/buildserver/achievements/UserEventsListener.java
// public interface UserEventsListener extends EventListener {
//   void userEventPublished(@NotNull User user, @NotNull String eventName, @Nullable Object additionalData);
// }
// 
// Path: achievements-server/src/main/java/org/jetbrains/buildserver/achievements/UserEventsRegistry.java
// public interface UserEventsRegistry {
//   @NotNull
//   UserEvents getUserEvents(@NotNull User user);
// 
//   void addListener(@NotNull UserEventsListener listener);
// 
//   void removeListener(@NotNull UserEventsListener listener);
// }


import jetbrains.buildServer.users.SUser;
import jetbrains.buildServer.users.User;
import jetbrains.buildServer.vcs.SVcsModification;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.buildserver.achievements.AchievementEvents;
import org.jetbrains.buildserver.achievements.UserEvents;
import org.jetbrains.buildserver.achievements.UserEventsListener;
import org.jetbrains.buildserver.achievements.UserEventsRegistry;
import java.util.Calendar;
import java.util.Date;
/*
 * Copyright 2000-2021 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jetbrains.buildserver.achievements.impl;



public class ProductivityBoost extends SimpleAchievement {
  public ProductivityBoost(@NotNull final UserEventsRegistry userEventsRegistry) {
    super(AchievementEvents.changeAdded.name(), 20);
    userEventsRegistry.addListener(new UserEventsListener() {
      public void userEventPublished(@NotNull User user, @NotNull String eventName, @Nullable Object additionalData) {
        if (!AchievementEvents.changeAdded.name().equals(eventName)) return;
        if (!(additionalData instanceof SVcsModification)) return;

        SVcsModification mod = (SVcsModification) additionalData;
        Date vcsDate = mod.getVcsDate();
        if (Calendar.getInstance().getTime().getTime() - vcsDate.getTime() < 24 * 3600 * 1000) {
// Path: achievements-server/src/main/java/org/jetbrains/buildserver/achievements/AchievementEvents.java
// public enum AchievementEvents {
//   buildUnpinned,
//   buildTagged,
//   testBombed,
//   testDisarmed,
//   compilationBroken,
//   investigationDelegated,
//   investigationTaken,
//   issueMentioned,
//   changeAdded,
//   userAction // with 5 minutes resolution
// }
// 
// Path: achievements-server/src/main/java/org/jetbrains/buildserver/achievements/UserEvents.java
// public interface UserEvents {
//   void registerEvent(@NotNull String eventName);
// 
//   void registerEvent(@NotNull String eventName, @Nullable Object additionalData);
// 
//   long getLastEventTime(@NotNull String eventName);
// 
//   // most recent first
//   @NotNull
//   List<Long> getEventTimes(@NotNull String eventName);
// 
//   int getNumberOfEvents(@NotNull String eventName);
// 
//   float getEventsRate(@NotNull String eventName, int timeIntervalSeconds);
// }
// 
// Path: achievements-server/src/main/java/org/jetbrains/buildserver/achievements/UserEventsListener.java
// public interface UserEventsListener extends EventListener {
//   void userEventPublished(@NotNull User user, @NotNull String eventName, @Nullable Object additionalData);
// }
// 
// Path: achievements-server/src/main/java/org/jetbrains/buildserver/achievements/UserEventsRegistry.java
// public interface UserEventsRegistry {
//   @NotNull
//   UserEvents getUserEvents(@NotNull User user);
// 
//   void addListener(@NotNull UserEventsListener listener);
// 
//   void removeListener(@NotNull UserEventsListener listener);
// }


// Path: achievements-server/src/main/java/org/jetbrains/buildserver/achievements/impl/ProductivityBoost.java
import jetbrains.buildServer.users.SUser;
import jetbrains.buildServer.users.User;
import jetbrains.buildServer.vcs.SVcsModification;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.buildserver.achievements.AchievementEvents;
import org.jetbrains.buildserver.achievements.UserEvents;
import org.jetbrains.buildserver.achievements.UserEventsListener;
import org.jetbrains.buildserver.achievements.UserEventsRegistry;
import java.util.Calendar;
import java.util.Date;

/*
 * Copyright 2000-2021 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jetbrains.buildserver.achievements.impl;



public class ProductivityBoost extends SimpleAchievement {
  public ProductivityBoost(@NotNull final UserEventsRegistry userEventsRegistry) {
    super(AchievementEvents.changeAdded.name(), 20);
    userEventsRegistry.addListener(new UserEventsListener() {
      public void userEventPublished(@NotNull User user, @NotNull String eventName, @Nullable Object additionalData) {
        if (!AchievementEvents.changeAdded.name().equals(eventName)) return;
        if (!(additionalData instanceof SVcsModification)) return;

        SVcsModification mod = (SVcsModification) additionalData;
        Date vcsDate = mod.getVcsDate();
        if (Calendar.getInstance().getTime().getTime() - vcsDate.getTime() < 24 * 3600 * 1000) {
          userEventsRegistry.getUserEvents(user).registerEvent(getId() + ":changeAdded");