import { defineStore } from 'pinia';
import { getDefaultEvent } from '@/api/system/gameEvent';
import { GameEventVO } from '@/api/system/gameEvent/types';

export const useGameEventStore = defineStore('gameEvent', {
  state: () => ({
    defaultEventInfo: null as GameEventVO | null,
  }),
  actions: {
    /**
     * 从API获取默认赛事信息并更新store
     */
    async fetchDefaultEvent() {
      try {
        const res = await getDefaultEvent();
        if (res.code === 200 && res.data) {
          this.defaultEventInfo = res.data;
        } else {
          this.defaultEventInfo = null;
        }
      } catch (error) {
        console.error('获取默认赛事信息失败:', error);
        this.defaultEventInfo = null;
      }
    },
    /**
     * 直接更新store中的默认赛事信息
     * @param eventInfo 新的默认赛事信息
     */
    updateDefaultEvent(eventInfo: GameEventVO | null) {
      this.defaultEventInfo = eventInfo;
    },
  },
}); 