package com.cloudbees.jenkins;

import javax.servlet.http.HttpServletRequest;
import jenkins.scm.api.SCMEvent;

/**
 * Encapsulates an event for {@link GitHubTrigger2}.
 *
 * @since TODO
 */
public class GitHubTriggerEvent {

    /**
     * The timestamp of the event (or if unavailable when the event was received)
     */
    private final long timestamp;
    /**
     * The origin of the event (see {@link SCMEvent#originOf(HttpServletRequest)})
     */
    private final String origin;
    /**
     * The user that the event was provided by.
     */
    private final String triggeredByUser;

    private GitHubTriggerEvent(long timestamp, String origin, String triggeredByUser) {
        this.timestamp = timestamp;
        this.origin = origin;
        this.triggeredByUser = triggeredByUser;
    }

    public static Builder create() {
        return new Builder();
    }

    public long getTimestamp() {
        return timestamp;
    }

    public String getOrigin() {
        return origin;
    }

    public String getTriggeredByUser() {
        return triggeredByUser;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        GitHubTriggerEvent that = (GitHubTriggerEvent) o;

        if (timestamp != that.timestamp) {
            return false;
        }
        if (origin != null ? !origin.equals(that.origin) : that.origin != null) {
            return false;
        }
        return triggeredByUser != null ? triggeredByUser.equals(that.triggeredByUser) : that.triggeredByUser == null;
    }

    @Override
    public int hashCode() {
        int result = (int) (timestamp ^ (timestamp >>> 32));
        result = 31 * result + (origin != null ? origin.hashCode() : 0);
        result = 31 * result + (triggeredByUser != null ? triggeredByUser.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "GitHubTriggerEvent{" +
                "timestamp=" + timestamp +
                ", origin='" + origin + '\'' +
                ", triggeredByUser='" + triggeredByUser + '\'' +
                '}';
    }

    /**
     * Builder for {@link GitHubTriggerEvent} instances..
     */
    public static class Builder {
        private long timestamp;
        private String origin;
        private String triggeredByUser;

        private Builder() {
            timestamp = System.currentTimeMillis();
        }

        public Builder withTimestamp(long timestamp) {
            this.timestamp = timestamp;
            return this;
        }

        public Builder withOrigin(String origin) {
            this.origin = origin;
            return this;
        }

        public Builder withTriggeredByUser(String triggeredByUser) {
            this.triggeredByUser = triggeredByUser;
            return this;
        }

        public GitHubTriggerEvent build() {
            return new GitHubTriggerEvent(timestamp, origin, triggeredByUser);
        }

        @Override
        public String toString() {
            return "GitHubTriggerEvent.Builder{" +
                    "timestamp=" + timestamp +
                    ", origin='" + origin + '\'' +
                    ", triggeredByUser='" + triggeredByUser + '\'' +
                    '}';
        }
    }
}

@@ -179,12 +179,14 @@
 nce 
-TODO
+1.25.2
 %0A */
@@ -2046,18 +2046,16 @@
 rEvent%7B%22
- +
 %0A       
@@ -2054,32 +2054,34 @@
 %0A               
+ +
  %22timestamp=%22 + 
@@ -2081,34 +2081,32 @@
 mp=%22 + timestamp
- +
 %0A               
@@ -2097,32 +2097,34 @@
 %0A               
+ +
  %22, origin='%22 + 
@@ -2128,34 +2128,32 @@
  + origin + '%5C''
- +
 %0A               
@@ -2144,32 +2144,34 @@
 %0A               
+ +
  %22, triggeredByU
@@ -2193,34 +2193,32 @@
 redByUser + '%5C''
- +
 %0A               
@@ -2209,32 +2209,34 @@
 %0A               
+ +
  '%7D';%0A    %7D%0A%0A   
@@ -3179,18 +3179,16 @@
 uilder%7B%22
- +
 %0A       
@@ -3199,16 +3199,18 @@
         
+ +
  %22timest
@@ -3226,18 +3226,16 @@
 imestamp
- +
 %0A       
@@ -3242,24 +3242,26 @@
             
+ +
  %22, origin='
@@ -3273,26 +3273,24 @@
 rigin + '%5C''
- +
 %0A           
@@ -3297,16 +3297,18 @@
         
+ +
  %22, trig
@@ -3346,18 +3346,16 @@
 r + '%5C''
- +
 %0A       
@@ -3366,16 +3366,18 @@
         
+ +
  '%7D';%0A  

Fix checkstyle errors