import { ofType } from 'redux-observable';
import { concat, of } from 'rxjs';
import { switchMap } from 'rxjs/operators';

import { createLiveEventFlowAction, createLiveStreamAction } from '../slices';
import { contentOwnerIdSelector } from '@/modules/liveEvents/liveEvent/redux/selectors';

export default (action$, state$) =>
  action$.pipe(
    ofType(createLiveEventFlowAction.type),
    switchMap(() => {
      const contentOwnerId = contentOwnerIdSelector(state$.value);
      return concat(of(createLiveStreamAction({ contentOwner: contentOwnerId })));
    }),
  );
