import { defineStore } from "pinia";
import apiError from '@/module/apiError.js';

export default defineStore('performanceStore', {
  state: () => ({
    allPerformanceData: null,
  }),
  getters: {
    performanceData: state => {
      return state.allPerformanceData;
    },
  },
  actions: {
    /**
     * Get Performance
     */
    async getPerformance(type, id) {
      let api = '';

      switch (type) {
        case 'log':
          api = `/api/logs/${id}/performance`;
          break;
        case 'filter':
          api = `/api/filters/${id}/performance`;
          break;
      }
      try {
        const response = await this.$axios.get(api);
        this.allPerformanceData = response.data;
      } catch(error) {
        apiError(error, 'Failed to load the Performance.');
      }
    }
  },
})
