1import api from '@/store/api';
2import i18n from '@/i18n';
3
4const SystemStore = {
5  namespaced: true,
6  state: {
7    systems: [],
8  },
9  getters: {
10    systems: (state) => state.systems,
11  },
12  mutations: {
13    setSystemInfo: (state, data) => {
14      const system = {};
15      system.assetTag = data.AssetTag;
16      system.description = data.Description;
17      system.firmwareVersion = data.BiosVersion;
18      system.hardwareType = data.Name;
19      system.health = data.Status?.Health;
20      system.id = data.Id;
21      system.locationIndicatorActive = data.LocationIndicatorActive;
22      system.locationNumber = data.LocationNumber;
23      system.manufacturer = data.Manufacturer;
24      system.memorySummaryHealth = data.MemorySummary?.Status.Health;
25      system.memorySummaryHealthRollup =
26        data.MemorySummary?.Status?.HealthRollup;
27      system.memorySummaryState = data.MemorySummary?.Status?.State;
28      system.model = data.Model;
29      system.processorSummaryCount = data.ProcessorSummary?.Count;
30      system.processorSummaryHealth = data.ProcessorSummary?.Status?.Health;
31      system.processorSummaryHealthRoll =
32        data.ProcessorSummary?.Status.HealthRollup;
33      system.processorSummaryState = data.ProcessorSummary?.Status?.State;
34      system.powerState = data.PowerState;
35      system.serialNumber = data.SerialNumber;
36      system.healthRollup = data.Status?.HealthRollup;
37      system.subModel = data.SubModel;
38      system.statusState = data.Status?.State;
39      system.systemType = data.SystemType;
40      state.systems = [system];
41    },
42  },
43  actions: {
44    async getSystem({ commit }) {
45      return await api
46        .get('/redfish/v1')
47        .then((response) =>
48          api.get(`${response.data.Systems['@odata.id']}/system`)
49        )
50        .then(({ data }) => commit('setSystemInfo', data))
51        .catch((error) => console.log(error));
52    },
53    async changeIdentifyLedState({ commit }, ledState) {
54      return await api
55        .patch('/redfish/v1/Systems/system', {
56          LocationIndicatorActive: ledState,
57        })
58        .catch((error) => {
59          commit('setSystemInfo', this.state.system.systems[0]);
60          console.log('error', error);
61          if (ledState) {
62            throw new Error(
63              i18n.t('pageInventory.toast.errorEnableIdentifyLed')
64            );
65          } else {
66            throw new Error(
67              i18n.t('pageInventory.toast.errorDisableIdentifyLed')
68            );
69          }
70        });
71    },
72  },
73};
74
75export default SystemStore;
76