// --------------- LIBRARIES ---------------
import { put, call, takeEvery, all } from 'redux-saga/effects';
import * as actions from '../slices';
import api from '../../api';
function* AuthenticateUserRequest(action) {
  try {
    const response = yield call(api.auth.authenticateUser, {
      payload: action.payload.payload,
      environment: action.payload.environment
    });
    if (Number(response.code) === -1) {
      throw new Error("Session Expire");
    } else if (Number(response.code) === 0) {
      throw new Error(response.message);
    }
    yield put(actions.authenticateUserSuccess(response));
    action.payload.resolve(response);
  } catch (error) {
    yield put(actions.authenticateUserError(error instanceof Error ? error === null || error === void 0 ? void 0 : error.message : "Something went wrong"));
    action.payload.reject(error);
  }
}
export function* AuthSaga() {
  yield all([takeEvery(actions.authenticateUserRequest.type, AuthenticateUserRequest)]);
}
export default AuthSaga;
//# sourceMappingURL=AuthSaga.js.map