/* global fetch */

import { all, takeLatest } from 'redux-saga/effects'
import es6promise from 'es6-promise'
import {
  requestSubscribeUserToPushSaga, requestResetPasswordSaga,
  verifyUserSaga, requestUpdateUserSaga, requestConfirmationAccountSaga,
  sendConfirmationEmailSaga, requestLoginSaga, requestUserSaga,
  requestRegisterSaga, requestLogoutSaga, requestNewsletterSubscribitionSaga,
  requestUpdateUserRequestSaga, requestUserSubscriptionToPushSaga
} from './sagas/userSaga.js'
import { requestAdsSaga, requestAdSaga, requestEmphasisJobsSaga, countAdViewRequestSaga } from './sagas/offreSaga.js'
import { requestCompaniesSaga, requestCompanySaga, requestEmphasisCompaniesSaga, countCompanyViewRequestSaga } from './sagas/companySaga.js'
import { postAnswerMessageSaga, postAdAnswerRequestSaga, uploadMediaSaga, uploadMediaPresSaga, uploadMediaCvSaga, fetchJobsAnsweredRequestSaga, fetchAnswerRequestSaga, fetchAnswerMessagesRequestSaga } from './sagas/answerSaga.js'

import {
  REQUEST_LOGIN,
  REQUEST_LOGOUT,
  REQUEST_REGISTER,
  FETCH_CURRENT_USER_REQUEST,
  FETCH_JOBS_REQUEST,
  FETCH_JOB_REQUEST,
  FETCH_EMPHASIS_JOBS_REQUEST,
  FETCH_EMPHASIS_COMPANIES_REQUEST,
  FETCH_COMPANIES_REQUEST,
  FETCH_COMPANY_REQUEST,
  SUBSCRIBE_NEWSLETTER_REQUEST,
  SEND_CONFIRMATION_EMAIL_REQUEST,
  ACCOUNT_CONFIRMATION_REQUEST,
  POST_AD_ANSWER_REQUEST,
  UPLOAD_MEDIA_REQUEST,
  UPLOAD_MEDIA_PRES_REQUEST,
  UPLOAD_MEDIA_CV_REQUEST,
  UPDATE_USER_REQUEST,
  FETCH_JOBS_ANSWER_REQUEST,
  FETCH_ANSWER_REQUEST,
  VERIFY_USER_REQUEST,
  RESET_PASSWORD_REQUEST,
  SUBSCRIBE_USER_TO_PUSH_REQUEST,
  POST_MESSAGE_ANSWER_REQUEST,
  FETCH_ANSWER_MESAGES_REQUEST,
  COUNT_AD_VIEW,
  COUNT_COMPANY_VIEW,
  FETCH_USER_SUBSCRIPTION_TO_PUSH_REQUEST,
  UPDATE_USER_PICTURE_REQUEST
} from "./types";


es6promise.polyfill()


function* rootSaga() {
  yield all([
    takeLatest(REQUEST_LOGIN, requestLoginSaga),
    takeLatest(REQUEST_LOGOUT, requestLogoutSaga),
    takeLatest(REQUEST_REGISTER, requestRegisterSaga),
    takeLatest(FETCH_CURRENT_USER_REQUEST, requestUserSaga),
    takeLatest(UPDATE_USER_REQUEST, requestUpdateUserSaga),
    takeLatest(SUBSCRIBE_NEWSLETTER_REQUEST, requestNewsletterSubscribitionSaga),
    takeLatest(FETCH_JOBS_REQUEST, requestAdsSaga),
    takeLatest(FETCH_JOB_REQUEST, requestAdSaga),
    takeLatest(FETCH_EMPHASIS_JOBS_REQUEST, requestEmphasisJobsSaga),
    takeLatest(FETCH_EMPHASIS_COMPANIES_REQUEST, requestEmphasisCompaniesSaga),
    takeLatest(FETCH_COMPANIES_REQUEST, requestCompaniesSaga),
    takeLatest(FETCH_COMPANY_REQUEST, requestCompanySaga),
    takeLatest(SEND_CONFIRMATION_EMAIL_REQUEST, sendConfirmationEmailSaga),
    takeLatest(ACCOUNT_CONFIRMATION_REQUEST, requestConfirmationAccountSaga),
    takeLatest(POST_AD_ANSWER_REQUEST, postAdAnswerRequestSaga),
    takeLatest(UPLOAD_MEDIA_REQUEST, uploadMediaSaga),
    takeLatest(UPLOAD_MEDIA_PRES_REQUEST, uploadMediaPresSaga),
    takeLatest(UPLOAD_MEDIA_CV_REQUEST, uploadMediaCvSaga),
    takeLatest(FETCH_JOBS_ANSWER_REQUEST, fetchJobsAnsweredRequestSaga),
    takeLatest(FETCH_ANSWER_REQUEST, fetchAnswerRequestSaga),
    takeLatest(VERIFY_USER_REQUEST, verifyUserSaga),
    takeLatest(RESET_PASSWORD_REQUEST, requestResetPasswordSaga),
    takeLatest(SUBSCRIBE_USER_TO_PUSH_REQUEST, requestSubscribeUserToPushSaga),
    takeLatest(POST_MESSAGE_ANSWER_REQUEST, postAnswerMessageSaga),
    takeLatest(FETCH_ANSWER_MESAGES_REQUEST, fetchAnswerMessagesRequestSaga),
    takeLatest(COUNT_AD_VIEW, countAdViewRequestSaga),
    takeLatest(COUNT_COMPANY_VIEW, countCompanyViewRequestSaga),
    takeLatest(FETCH_USER_SUBSCRIPTION_TO_PUSH_REQUEST, requestUserSubscriptionToPushSaga),
    takeLatest(UPDATE_USER_PICTURE_REQUEST, requestUpdateUserRequestSaga)
  ])
}

export default rootSaga