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.totalSystemMemoryGiB = data.MemorySummary?.TotalSystemMemoryGiB;
21      system.id = data.Id;
22      system.locationIndicatorActive = data.LocationIndicatorActive;
23      system.locationNumber = data.Location?.PartLocation?.ServiceLabel;
24      system.manufacturer = data.Manufacturer;
25      system.memorySummaryHealth = data.MemorySummary?.Status.Health;
26      system.memorySummaryHealthRollup =
27        data.MemorySummary?.Status?.HealthRollup;
28      system.memorySummaryState = data.MemorySummary?.Status?.State;
29      system.model = data.Model;
30      system.processorSummaryCount = data.ProcessorSummary?.Count;
31      system.processorSummaryCoreCount = data.ProcessorSummary?.CoreCount;
32      system.processorSummaryHealth = data.ProcessorSummary?.Status?.Health;
33      system.processorSummaryHealthRoll =
34        data.ProcessorSummary?.Status.HealthRollup;
35      system.processorSummaryState = data.ProcessorSummary?.Status?.State;
36      system.powerState = data.PowerState;
37      system.serialNumber = data.SerialNumber;
38      system.healthRollup = data.Status?.HealthRollup;
39      system.subModel = data.SubModel;
40      system.statusState = data.Status?.State;
41      system.systemType = data.SystemType;
42      state.systems = [system];
43    },
44  },
45  actions: {
46    async getSystem({ commit }) {
47      return await api
48        .get('/redfish/v1')
49        .then((response) =>
50          api.get(`${response.data.Systems['@odata.id']}/system`)
51        )
52        .then(({ data }) => commit('setSystemInfo', data))
53        .catch((error) => console.log(error));
54    },
55    async changeIdentifyLedState({ commit }, ledState) {
56      return await api
57        .patch('/redfish/v1/Systems/system', {
58          LocationIndicatorActive: ledState,
59        })
60        .catch((error) => {
61          commit('setSystemInfo', this.state.system.systems[0]);
62          console.log('error', error);
63          if (ledState) {
64            throw new Error(
65              i18n.t('pageInventory.toast.errorEnableIdentifyLed')
66            );
67          } else {
68            throw new Error(
69              i18n.t('pageInventory.toast.errorDisableIdentifyLed')
70            );
71          }
72        });
73    },
74  },
75};
76
77export default SystemStore;
78