michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.fxa.login; michael@0: michael@0: import org.mozilla.gecko.fxa.login.FxAccountLoginStateMachine.ExecuteDelegate; michael@0: import org.mozilla.gecko.sync.ExtendedJSONObject; michael@0: import org.mozilla.gecko.sync.Utils; michael@0: michael@0: public abstract class State { michael@0: public static final long CURRENT_VERSION = 2L; michael@0: michael@0: public enum StateLabel { michael@0: Engaged, michael@0: Cohabiting, michael@0: Married, michael@0: Separated, michael@0: Doghouse, michael@0: } michael@0: michael@0: public enum Action { michael@0: NeedsUpgrade, michael@0: NeedsPassword, michael@0: NeedsVerification, michael@0: None, michael@0: } michael@0: michael@0: protected final StateLabel stateLabel; michael@0: public final String email; michael@0: public final String uid; michael@0: public final boolean verified; michael@0: michael@0: public State(StateLabel stateLabel, String email, String uid, boolean verified) { michael@0: Utils.throwIfNull(email, uid); michael@0: this.stateLabel = stateLabel; michael@0: this.email = email; michael@0: this.uid = uid; michael@0: this.verified = verified; michael@0: } michael@0: michael@0: public StateLabel getStateLabel() { michael@0: return this.stateLabel; michael@0: } michael@0: michael@0: public ExtendedJSONObject toJSONObject() { michael@0: ExtendedJSONObject o = new ExtendedJSONObject(); michael@0: o.put("version", State.CURRENT_VERSION); michael@0: o.put("email", email); michael@0: o.put("uid", uid); michael@0: o.put("verified", verified); michael@0: return o; michael@0: } michael@0: michael@0: public State makeSeparatedState() { michael@0: return new Separated(email, uid, verified); michael@0: } michael@0: michael@0: public State makeDoghouseState() { michael@0: return new Doghouse(email, uid, verified); michael@0: } michael@0: michael@0: public abstract void execute(ExecuteDelegate delegate); michael@0: michael@0: public abstract Action getNeededAction(); michael@0: }