public History recordStateTransition(Node.State from, Node.State to, Agent agent, Optional<String> reason, Instant at) {
        // If the event is a re-reservation, allow the new one to override the older one.
        if (from == to && from != Node.State.reserved) return this;
        // Only keeping reason for errored states (failed, parked)
        return switch (to) {
            case provisioned -> this.with(new Event(Event.Type.provisioned, agent, at));
            case deprovisioned -> this.with(new Event(Event.Type.deprovisioned, agent, at));
            case ready -> this.withoutApplicationEvents().with(new Event(Event.Type.readied, agent, at));
            case active -> this.with(new Event(Event.Type.activated, agent, at));
            case inactive -> this.with(new Event(Event.Type.deactivated, agent, at));
            case reserved -> this.with(new Event(Event.Type.reserved, agent, at));
            case failed -> this.with(new Event(Event.Type.failed, agent, at, reason));
            case dirty -> this.with(new Event(Event.Type.deallocated, agent, at));
            case parked -> this.with(new Event(Event.Type.parked, agent, at, reason));
            case breakfixed -> this.with(new Event(Event.Type.breakfixed, agent, at));
        };
    }
Returns a copy of this history with a record of this state transition added, if applicable
node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/History.java