"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useSpecStoreState = exports.useSpecActions = exports.specActions = exports.specsSlice = exports.defaultSpecsState = void 0;

var _toolkit = require("@reduxjs/toolkit");

var _redux = require("@looker/redux");

var _sagas = require("./sagas");

var defaultSpecsState = {
  specs: {},
  currentSpecKey: '',
  working: true,
  description: undefined
};
exports.defaultSpecsState = defaultSpecsState;
var specsSlice = (0, _toolkit.createSlice)({
  name: 'specs',
  initialState: defaultSpecsState,
  reducers: {
    initSpecsAction(state, _action) {
      state.working = true;
      state.description = 'Fetching specifications...';
    },

    initSpecsSuccessAction(state, action) {
      state.specs = action.payload.specs;
      state.currentSpecKey = action.payload.currentSpecKey;
      state.working = false;
      state.description = undefined;
    },

    initSpecsFailureAction(state, action) {
      state.working = false;
      state.error = action.payload;
    },

    setCurrentSpecAction(state, action) {
      state.working = true;
      state.description = "Fetching API ".concat(action.payload.currentSpecKey, " spec");
    },

    setCurrentSpecSuccessAction(state, action) {
      state.currentSpecKey = action.payload.currentSpecKey;
      state.specs[state.currentSpecKey].api = action.payload.api;
      state.description = undefined;
      state.working = false;
    },

    setCurrentSpecFailureAction(state, action) {
      state.working = false;
      state.error = action.payload;
    }

  }
});
exports.specsSlice = specsSlice;
var specActions = specsSlice.actions;
exports.specActions = specActions;
var {
  useActions: useSpecActions,
  useStoreState: useSpecStoreState
} = (0, _redux.createSliceHooks)(specsSlice, _sagas.saga);
exports.useSpecStoreState = useSpecStoreState;
exports.useSpecActions = useSpecActions;
//# sourceMappingURL=slice.js.map