// import { AnyAction } from 'redux'
// import { ActionsObservable, combineEpics, ofType } from 'redux-observable'
// import { from, of } from 'rxjs'
// import { catchError, switchMap, tap } from 'rxjs/operators'

// import { session } from '@agiliza/api/useCases'
// import { actions as sessionActions, types as sessionTypes } from '@agiliza/redux/session'
// import { actions as loginActions, types as loginTypes } from '@agiliza/redux/ui/login'

// type LoginRequestAction = ReturnType<typeof loginActions.login>

// const loginEpic = (action$: ActionsObservable<LoginRequestAction>) =>
//   action$.pipe(
//     ofType<AnyAction, LoginRequestAction>(loginTypes.login),
//     switchMap((action) =>
//       from(session.login(action.payload)).pipe(
//         switchMap(() => {
//           return of(loginActions.loginSuccess(), sessionActions.authSuccess())
//         }),
//         catchError((error) => of(loginActions.loginError(error)))
//       )
//     )
//   )
// type LogoutRequestAction = ReturnType<typeof sessionActions.logout>

// const logoutEpic = (action$: ActionsObservable<AnyAction>) =>
//   action$.pipe(
//     ofType<AnyAction, LogoutRequestAction>(sessionTypes.logout),
//     tap(() => void session.logout()),
//     switchMap(() => of(sessionActions.logoutSuccess(), { type: 'RESET_STORE' }))
//   )

// type InitializeRequestAction = ReturnType<typeof sessionActions.initialize>

// const initializeEpic = (action$: ActionsObservable<InitializeRequestAction>) =>
//   action$.pipe(
//     ofType<AnyAction, InitializeRequestAction>(sessionTypes.initialize),
//     switchMap(() =>
//       from(session.initialize()).pipe(
//         switchMap(() => {
//           return of(sessionActions.initializeSuccess())
//         }),
//         catchError((error) => of(sessionActions.initializeError(error)))
//       )
//     )
//   )

// export default combineEpics(loginEpic, logoutEpic, initializeEpic)
