package leigh.elements.sdk.actions;

import leigh.elements.sdk.AppScreenInstance;

import java.util.Objects;

/**
 * This action indicates that a screen should be opened on the client.
 *
 * @author Alex Leigh
 */
public class ScreenOpenAction implements ScreenAction {
    private final AppScreenInstance screenInstance;
    private final boolean closeOriginatingScreen;

    public ScreenOpenAction(AppScreenInstance screenInstance) {
        this(screenInstance, false);
    }

    public ScreenOpenAction(AppScreenInstance screenInstance, boolean closeOriginatingScreen) {
        this.screenInstance = screenInstance;
        this.closeOriginatingScreen = closeOriginatingScreen;
    }

    public AppScreenInstance getScreenInstance() {
        return screenInstance;
    }

    /**
     * <code>true</code> if the recipient should also close the originating screen of this event.
     */
    public boolean isCloseOriginatingScreen() {
        return closeOriginatingScreen;
    }

    @Override
    public String toString() {
        return "ScreenOpenAction{" +
                "screenInstance=" + screenInstance +
                ", closeOriginatingScreen=" + closeOriginatingScreen +
                '}';
    }

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

    @Override
    public int hashCode() {
        return Objects.hash(screenInstance);
    }
}
