text: /* eslint-disable indent */
  import {takeEvery, takeLatest} from 'redux-saga/effects';
  import * as credentialInfoAPI from '../api/credentialInfo'; // api/credentialInfo 안의 함수 모두 불러오기
  import {
      reducerUtils,
      handleAsyncActions,
      createPromiseSaga
  } from '../lib/asyncUtils';
  
  /* 액션 타입 */
  const SET_SELECTED_SERVER = 'credential-info/SET_SELECTED_SERVER';
  const CLEAR_SELECTED_SERVER = 'credential-info/CLEAR_SELECTED_SERVER';
  
  const SEARCH_CREDENTIAL_INFO = 'credential-info/SEARCH_CREDENTIAL_INFO'; // 요청 시작
  const SEARCH_CREDENTIAL_INFO_SUCCESS =
      'credential-info/SEARCH_CREDENTIAL_INFO_SUCCESS'; // 요청 성공
  const SEARCH_CREDENTIAL_INFO_ERROR =
      'credential-info/SEARCH_CREDENTIAL_INFO_ERROR'; // 요청 실패
  const CLEAR_SEARCH_CREDENTIAL_INFO =
      'credential-info/CLEAR_SEARCH_CREDENTIAL_INFO';
  
  const CREATE_CREDENTIAL_INFO = 'credential-info/CREATE_CREDENTIAL_INFO'; // 요청 시작
  const CREATE_CREDENTIAL_INFO_SUCCESS =
      'credential-info/CREATE_CREDENTIAL_INFO_SUCCESS'; // 요청 성공
  const CREATE_CREDENTIAL_INFO_ERROR =
      'credential-info/CREATE_CREDENTIAL_INFO_ERROR'; // 요청 실패
  const CLEAR_CREATE_CREDENTIAL_INFO =
      'credential-info/CLEAR_CREATE_CREDENTIAL_INFO';
  
  const UPDATE_CREDENTIAL_INFO = 'credential-info/UPDATE_CREDENTIAL_INFO'; // 요청 시작
  const UPDATE_CREDENTIAL_INFO_SUCCESS =
      'credential-info/UPDATE_CREDENTIAL_INFO_SUCCESS'; // 요청 성공
  const UPDATE_CREDENTIAL_INFO_ERROR =
      'credential-info/UPDATE_CREDENTIAL_INFO_ERROR'; // 요청 실패
  const CLEAR_UPDATE_CREDENTIAL_INFO =
      'credential-info/CLEAR_UPDATE_CREDENTIAL_INFO';
  
  const DELETE_CREDENTIAL_INFO = 'credential-info/DELETE_CREDENTIAL_INFO'; // 요청 시작
  const DELETE_CREDENTIAL_INFO_SUCCESS =
      'credential-info/DELETE_CREDENTIAL_INFO_SUCCESS'; // 요청 성공
  const DELETE_CREDENTIAL_INFO_ERROR =
      'credential-info/DELETE_CREDENTIAL_INFO_ERROR'; // 요청 실패
  const CLEAR_DELETE_CREDENTIAL_INFO =
      'credential-info/CLEAR_DELETE_CREDENTIAL_INFO';
  
  // selectedServerId
  export const setSelectedServer = (selectedServer) => ({
      type: SET_SELECTED_SERVER,
      payload: {
          selectedServer: {
              ...selectedServer
          }
      }
  });
  
  export const clearSelectedServer = () => ({
      type: CLEAR_SELECTED_SERVER
  });
  
  // search
  export const searchCredentialInfo = (serverId, page, size) => ({
      type: SEARCH_CREDENTIAL_INFO,
      payload: {
          serverId,
          page,
          size
      }
  });
  
  export const clearSearchCredentialInfo = () => ({
      type: CLEAR_SEARCH_CREDENTIAL_INFO
  });
  
  // create
  export const createCredentialInfo = (
      credentialName,
      description,
      userId,
      password,
      isDefault,
      serverId
  ) => ({
      type: CREATE_CREDENTIAL_INFO,
      payload: {
          credentialName,
          description,
          userId,
          password,
          isDefault,
          serverId
      }
  });
  
  export const clearCreateCredentialInfo = () => ({
      type: CLEAR_CREATE_CREDENTIAL_INFO
  });
  
  // update
  export const updateCredentialInfo = (
      credentialInfoId,
      credentialName,
      description,
      userId,
      password,
      isDefault,
      serverId
  ) => ({
      type: UPDATE_CREDENTIAL_INFO,
      payload: {
          credentialInfoId,
          credentialName,
          description,
          userId,
          password,
          isDefault,
          serverId
      }
  });
  
  export const clearUpdateCredentialInfo = () => ({
      type: CLEAR_UPDATE_CREDENTIAL_INFO
  });
  
  // delete
  export const deleteCredentialInfo = (credentialInfoId) => ({
      type: DELETE_CREDENTIAL_INFO,
      payload: {
          credentialInfoId
      }
  });
  
  export const clearDeleteCredentialInfo = () => ({
      type: CLEAR_DELETE_CREDENTIAL_INFO
  });
  
  const searchCredentialInfoSaga = createPromiseSaga(
      SEARCH_CREDENTIAL_INFO,
      credentialInfoAPI.searchCredentialInfo
  );
  
  const createCredentialInfoSaga = createPromiseSaga(
      CREATE_CREDENTIAL_INFO,
      credentialInfoAPI.createCredentialInfo
  );
  
  const updateCredentialInfoSaga = createPromiseSaga(
      UPDATE_CREDENTIAL_INFO,
      credentialInfoAPI.updateCredentialInfo
  );
  
  const deleteCredentialInfoSaga = createPromiseSaga(
      DELETE_CREDENTIAL_INFO,
      credentialInfoAPI.deleteCredentialInfo
  );
  
  // 사가들을 합치기
  export function* credentialInfoSaga() {
      yield takeLatest(SEARCH_CREDENTIAL_INFO, searchCredentialInfoSaga);
      yield takeEvery(CREATE_CREDENTIAL_INFO, createCredentialInfoSaga);
      yield takeEvery(UPDATE_CREDENTIAL_INFO, updateCredentialInfoSaga);
      yield takeEvery(DELETE_CREDENTIAL_INFO, deleteCredentialInfoSaga);
  }
  
  // initialState 쪽도 반복되는 코드를 initial() 함수를 사용해서 리팩토링 했습니다.
  const initialState = {
      selectedServer: null,
      search: reducerUtils.initial(),
      create: reducerUtils.initial(),
      update: reducerUtils.initial(),
      delete: reducerUtils.initial()
  };
  
  export default function credentialInfo(state = initialState, action) {
      switch (action.type) {
          case SET_SELECTED_SERVER:
              return {
                  ...state,
                  selectedServer: action.payload.selectedServer
              };
          case CLEAR_SELECTED_SERVER:
              return {
                  ...state,
                  selectedServer: null
              };
          case SEARCH_CREDENTIAL_INFO:
          case SEARCH_CREDENTIAL_INFO_SUCCESS:
          case SEARCH_CREDENTIAL_INFO_ERROR:
              return handleAsyncActions(
                  SEARCH_CREDENTIAL_INFO,
                  'search',
                  true
              )(state, action);
          case CLEAR_SEARCH_CREDENTIAL_INFO:
              return {
                  ...state,
                  search: reducerUtils.initial()
              };
          case CREATE_CREDENTIAL_INFO:
          case CREATE_CREDENTIAL_INFO_SUCCESS:
          case CREATE_CREDENTIAL_INFO_ERROR:
              return handleAsyncActions(
                  CREATE_CREDENTIAL_INFO,
                  'create',
                  true
              )(state, action);
          case CLEAR_CREATE_CREDENTIAL_INFO:
              return {
                  ...state,
                  create: reducerUtils.initial()
              };
          case UPDATE_CREDENTIAL_INFO:
          case UPDATE_CREDENTIAL_INFO_SUCCESS:
          case UPDATE_CREDENTIAL_INFO_ERROR:
              return handleAsyncActions(
                  UPDATE_CREDENTIAL_INFO,
                  'update',
                  true
              )(state, action);
          case CLEAR_UPDATE_CREDENTIAL_INFO:
              return {
                  ...state,
                  update: reducerUtils.initial()
              };
          case DELETE_CREDENTIAL_INFO:
          case DELETE_CREDENTIAL_INFO_SUCCESS:
          case DELETE_CREDENTIAL_INFO_ERROR:
              return handleAsyncActions(
                  DELETE_CREDENTIAL_INFO,
                  'delete',
                  true
              )(state, action);
          case CLEAR_DELETE_CREDENTIAL_INFO:
              return {
                  ...state,
                  delete: reducerUtils.initial()
              };
          default:
              return state;
      }
  }
  