import {defineStore} from 'pinia';

export const useModel = defineStore('model', {
  state: () => ({
    name: '',
    status: 'loading',
    availableModels: [] as string[],
    error: null as string | null
  }),
  actions: {
    async loadModelStatus() {
      try {
        const response = await fetch('/model/status');
        if (!response.ok) {
          throw new Error('Failed to fetch model status');
        }
        const data = await response.json();
        this.name = data.name;
        this.status = data.status;
        this.availableModels = data.available_models || [];
        this.error = null;
      } catch (e) {
        this.status = 'error';
        this.error = e instanceof Error ? e.message : 'Unknown error';
      }
    }
  }
});
