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