import { defineStore } from 'pinia';
import { ApiStatusRepository } from '../../infrastructure/api/ApiStatusRepository';

const statusRepository = new ApiStatusRepository();

export const useStatusStore = defineStore('system-status', {
    state: () => ({
        status: null,
        loading: false,
        error: null,
    }),

    actions: {
        async loadStatus() {
            this.loading = true;
            this.error = null;
            try {
                this.status = await statusRepository.getStatus();
            } catch (e) {
                this.error = e.message ?? 'Erreur lors du chargement du statut système';
            } finally {
                this.loading = false;
            }
        },
    },
});
