001package gudusoft.gsqlparser.runtime;
002
003/**
004 * The outcome of an {@link GspRuntime#activate(byte[])} call.
005 *
006 * <p>Immutable and safe to publish to logs. It deliberately carries no part of
007 * the entitlement itself.</p>
008 *
009 * @since 4.2.7
010 */
011public final class GspActivation {
012
013    private final GspActivationStatus status;
014    private final String auditId;
015    private final String deploymentId;
016    private final long expiresAtEpochSeconds;
017
018    GspActivation(GspActivationStatus status, String auditId,
019                  String deploymentId, long expiresAtEpochSeconds) {
020        this.status = status;
021        this.auditId = auditId;
022        this.deploymentId = deploymentId;
023        this.expiresAtEpochSeconds = expiresAtEpochSeconds;
024    }
025
026    /** @return why the entitlement was accepted or rejected; never null. */
027    public GspActivationStatus getStatus() {
028        return status;
029    }
030
031    /** @return true only when parsing is permitted. */
032    public boolean isValid() {
033        return status.isValid();
034    }
035
036    /** @return the stable reason code, for the host's own log line. */
037    public String reasonCode() {
038        return status.name();
039    }
040
041    /**
042     * A short random id minted per activation attempt and written to GSP's own
043     * log at the refusal point.
044     *
045     * <p>Log it. It is what lets support correlate a customer's "it just stopped
046     * working" against the exact refusal, which is the condition on which covert
047     * refusal was agreed at all.</p>
048     *
049     * @return the audit id; never null
050     */
051    public String auditId() {
052        return auditId;
053    }
054
055    /** @return the entitlement's deployment/licence id, or null when not accepted. */
056    public String deploymentId() {
057        return deploymentId;
058    }
059
060    /** @return expiry as epoch seconds, or 0 when not accepted or non-expiring. */
061    public long expiresAtEpochSeconds() {
062        return expiresAtEpochSeconds;
063    }
064
065    @Override
066    public String toString() {
067        return "GspActivation{status=" + status
068                + ", auditId=" + auditId
069                + ", deploymentId=" + deploymentId
070                + ", expiresAt=" + expiresAtEpochSeconds + "}";
071    }
072}