/**
 * JBoss, Home of Professional Open Source.
 * Copyright 2014-2020 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * 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.jboss.pnc.dto.notification;

import org.jboss.pnc.dto.Build;
import org.jboss.pnc.enums.BuildStatus;

import lombok.Data;

import org.jboss.pnc.enums.JobNotificationProgress;
import org.jboss.pnc.enums.JobNotificationType;

import static org.jboss.pnc.enums.BuildStatus.NEW;
import static org.jboss.pnc.enums.BuildStatus.WAITING_FOR_DEPENDENCIES;
import static org.jboss.pnc.enums.JobNotificationProgress.FINISHED;
import static org.jboss.pnc.enums.JobNotificationProgress.IN_PROGRESS;
import static org.jboss.pnc.enums.JobNotificationProgress.PENDING;
import static org.jboss.pnc.enums.JobNotificationType.BUILD;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * Notification about change in Build.
 * 
 * <pre>
 * Job: {@link JobNotificationType#BUILD} Notification type: {@code BUILD_STATUS_CHANGED} Progress:
 * {@link JobNotificationProgress#PENDING} - build is new or waiting for dependencies
 * {@link JobNotificationProgress#IN_PROGRESS} - build is not in a final state {@link JobNotificationProgress#FINISHED}
 * - build is in final state Message: no
 * 
 * <pre>
 * 
 * @author Honza Brázdil &lt;jbrazdil@redhat.com&gt;
 */
@Data
public class BuildChangedNotification extends Notification {

    private static final String BUILD_STATUS_CHANGED = "BUILD_STATUS_CHANGED";

    /**
     * Previous status of the build.
     */
    private final BuildStatus oldStatus;

    /**
     * Build entity in the new state.
     */
    private final Build build;

    @JsonCreator
    public BuildChangedNotification(
            @JsonProperty("oldStatus") BuildStatus oldStatus,
            @JsonProperty("build") Build build) {
        super(BUILD, BUILD_STATUS_CHANGED, getProgress(build.getStatus()), getProgress(oldStatus));
        this.oldStatus = oldStatus;
        this.build = build;
    }

    public static JobNotificationProgress getProgress(BuildStatus status) {
        if (status == null) {
            return null;
        }
        if (status == WAITING_FOR_DEPENDENCIES || status == NEW) {
            return PENDING;
        }
        if (status.isFinal()) {
            return FINISHED;
        } else {
            return IN_PROGRESS;
        }
    }
}

@@ -754,94 +754,159 @@
 ort 
-org.jboss.pnc.dto.Build;%0Aimport org.jboss.pnc.enums.BuildStatus;%0A%0Aimport lombok.Data;%0A
+com.fasterxml.jackson.annotation.JsonCreator;%0Aimport com.fasterxml.jackson.annotation.JsonProperty;%0Aimport lombok.Data;%0Aimport org.jboss.pnc.dto.Build;
 %0Aimp
@@ -925,39 +925,29 @@
 s.pnc.enums.
-JobNotification
+Build
 Progress;%0Aim
@@ -975,37 +975,28 @@
 ums.
-JobNotificationType;%0A
+BuildStatus;
 %0Aimport 
 stat
@@ -983,39 +983,32 @@
 dStatus;%0Aimport 
-static 
 org.jboss.pnc.en
@@ -1015,23 +1015,31 @@
 ums.
-BuildStatus.NEW
+JobNotificationProgress
 ;%0Aim
@@ -1035,39 +1035,32 @@
 rogress;%0Aimport 
-static 
 org.jboss.pnc.en
@@ -1067,45 +1067,29 @@
 ums.
-BuildStatus.WAITING_FOR_DEPENDENCIES;
+JobNotificationType;%0A
 %0Aimp
@@ -1357,116 +1357,8 @@
 D;%0A%0A
-import com.fasterxml.jackson.annotation.JsonCreator;%0Aimport com.fasterxml.jackson.annotation.JsonProperty;%0A%0A
 /**%0A
@@ -2343,14 +2343,47 @@
 per(
-BUILD,
+%0A                BUILD,%0A               
  BUI
@@ -2400,16 +2400,32 @@
 CHANGED,
+%0A               
  getProg
@@ -2450,10 +2450,37 @@
 us()
-),
+.progress()),%0A               
  get
@@ -2497,16 +2497,27 @@
 ldStatus
+.progress()
 ));%0A    
@@ -2642,21 +2642,23 @@
 ss(Build
-Statu
+Progres
 s status
@@ -2730,34 +2730,38 @@
   %7D%0A        
-if
+switch
  (status
  == WAITING_
@@ -2752,57 +2752,42 @@
 atus
- == WAITING_FOR_DEPENDENCIES %7C%7C status == NEW) %7B%0A
+) %7B%0A            case PENDING:%0A    
     
@@ -2822,42 +2822,31 @@
     
-%7D%0A
     
-    if (status.isFinal()) %7B%0A
+case FINISHED:%0A    
     
@@ -2882,17 +2882,34 @@
     
-%7D else %7B%0A
+    case IN_PROGRESS:%0A    
     
@@ -2936,16 +2936,122 @@
 OGRESS;%0A
+            default:%0A                throw new UnsupportedOperationException(%22Unknown status %22 + status);%0A
         

fix ENQUEUED status being IN_PROGRESS instead of PENDING