import { call, put, select } from 'redux-saga/effects';
import _ from 'lodash';
import * as types from '~/store/actionTypes';
import { Nixplay } from '~/lib/sdk';

import * as selectors from './selectors';

export function* reset() {
	try {
		const token = yield select(selectors.token);
		const user = yield select(selectors.username);
		if (!_.isEmpty(token) && !_.isEmpty(user)) {
			yield call(Nixplay.notification.reset, token, user);
			yield put({ type: types.RESET_NOTIFICATION_SUCCESS, payload: {} });
		} else {
			yield put({ type: types.RESET_NOTIFICATION_ERROR, payload: {} });
		}
	} catch (error) {
		yield put({ type: types.RESET_NOTIFICATION_ERROR, payload: { error } });
	}
}
