# State Manager

A utility model to help identify the current state of a user

For example:

```javascript
const { StateManager, PossibleUserStates, UserStates } = require('n-membership-sdk');
const stateManager = new StateManager(userData);
stateManager.setSubscriptionHistory(userSubscriptionHistory);
const userState = stateManager.identify();
```

## Table of Contents

* [UserStates](#userStates)
* [Properties](#properties)
* [Methods](#methods)
	* [setSubscriptionHistory](#setSubscriptionHistory)
	* [identify](#identify)


## UserStates

As of today, there are the following User states

*	TRANSITION
	* User has a future transition to an alternative offering.
*	DISCOUNT
	* User has a future discount to a cheaper offer with a subset of the current products.
	* This also includes Standard -> Standard.
*	CANCELLED
	* The user has a pending cancellation.
*	FROZEN
	* The user was in stepup and has had that stepup "undone" but not yet applied.
*	STEPUP
	* The user's subscription will shortly be increased in price.
*	TRIALIST
	* User is in their trial period.
*	DEFAULT
	* None of the previous states applied, fallback state.

## Properties

| Parameter Name       | Description                                                                |
| -------------------- | -------------------------------------------------------------------------- |
| userData             | A reference to the userData provided upon initialisation                   |
| subscriptionHistory  | A reference to the subscription history provided in setSubscriptionHistory |
| futureCancellation   | If found, a reference to a cancellation `SubscriptionHistoryModel`         |
| futureTransition     | If found, a reference to a transition `SubscriptionHistoryModel`           |

## Methods

### setSubscriptionHistory

```javascript
stateManager.setSubscriptionHistory(userSubHistoryResponse);
```

| Parameters           | Required | Type                     | Example           | Description                     |
| -------------------- | ---------| ------------------------ | ------------------|-------------------------------- |
| subscriptionHistory  | yes      | SubscriptionHistoryModel | N/A               | User's subscription history     |



### Identify

```javascript
const userState = stateManager.identify();
```

**Response**

A string equal to the value of one of the `UserStates`.
