// 
// Decompiled by Procyon v0.6.0
// 

package com.nimbusds.jose.jwk;

import java.text.ParseException;
import com.nimbusds.jwt.util.DateUtils;
import com.nimbusds.jose.util.JSONObjectUtils;
import java.util.Map;
import java.util.Objects;
import java.util.Date;
import com.nimbusds.jose.shaded.jcip.Immutable;
import java.io.Serializable;

@Immutable
public final class KeyRevocation implements Serializable
{
    private final Date revokedAt;
    private final Reason reason;
    
    public KeyRevocation(final Date revokedAt, final Reason reason) {
        this.revokedAt = Objects.requireNonNull(revokedAt);
        this.reason = reason;
    }
    
    public Date getRevocationTime() {
        return this.revokedAt;
    }
    
    public Reason getReason() {
        return this.reason;
    }
    
    @Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof KeyRevocation)) {
            return false;
        }
        final KeyRevocation that = (KeyRevocation)o;
        return Objects.equals(this.revokedAt, that.revokedAt) && Objects.equals(this.getReason(), that.getReason());
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.revokedAt, this.getReason());
    }
    
    public Map<String, Object> toJSONObject() {
        final Map<String, Object> o = JSONObjectUtils.newJSONObject();
        o.put("revoked_at", DateUtils.toSecondsSinceEpoch(this.getRevocationTime()));
        if (this.getReason() != null) {
            o.put("reason", this.getReason().getValue());
        }
        return o;
    }
    
    public static KeyRevocation parse(final Map<String, Object> jsonObject) throws ParseException {
        final Date revokedAt = DateUtils.fromSecondsSinceEpoch(JSONObjectUtils.getLong(jsonObject, "revoked_at"));
        Reason reason = null;
        if (jsonObject.get("reason") != null) {
            reason = Reason.parse(JSONObjectUtils.getString(jsonObject, "reason"));
        }
        return new KeyRevocation(revokedAt, reason);
    }
    
    public static class Reason
    {
        public static final Reason UNSPECIFIED;
        public static final Reason COMPROMISED;
        public static final Reason SUPERSEDED;
        private final String value;
        
        public Reason(final String value) {
            this.value = Objects.requireNonNull(value);
        }
        
        public String getValue() {
            return this.value;
        }
        
        @Override
        public String toString() {
            return this.getValue();
        }
        
        @Override
        public boolean equals(final Object o) {
            if (this == o) {
                return true;
            }
            if (!(o instanceof Reason)) {
                return false;
            }
            final Reason reason = (Reason)o;
            return Objects.equals(this.getValue(), reason.getValue());
        }
        
        @Override
        public int hashCode() {
            return Objects.hashCode(this.getValue());
        }
        
        public static Reason parse(final String s) {
            if (Reason.UNSPECIFIED.getValue().equals(s)) {
                return Reason.UNSPECIFIED;
            }
            if (Reason.COMPROMISED.getValue().equals(s)) {
                return Reason.COMPROMISED;
            }
            if (Reason.SUPERSEDED.getValue().equals(s)) {
                return Reason.SUPERSEDED;
            }
            return new Reason(s);
        }
        
        static {
            UNSPECIFIED = new Reason("unspecified");
            COMPROMISED = new Reason("compromised");
            SUPERSEDED = new Reason("superseded");
        }
    }
}
