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

export function* registerAssistance(action) {
	try {
		const response = yield call(API.assistance.registerAssistance, { payload: action.payload });
		yield put({ type: types.REQUEST_VALIDATE_ASSISTANCE_SUCCESS, payload: action.payload });
		yield call(action.payload.resolve, response);
	} catch (error) {
		yield put({ type: types.REQUEST_VALIDATE_ASSISTANCE_ERROR, payload: { error } });
		yield call(action.payload.reject, action, error);
	}
}
export function* verifyRefID(action) {
	try {
		const response = yield call(API.assistance.verifyRefID, { payload: action.payload });
		yield put({ type: types.REQUEST_VERIFY_REFID_SUCCESS, payload: action.payload });
		yield call(action.payload.resolve, response);
	} catch (error) {
		yield put({ type: types.REQUEST_VERIFY_REFID_ERROR, payload: { error } });
		yield call(action.payload.reject, action, error);
	}
}
