import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useActivityInfoStore = defineStore('activity-info', () => {
  const activityInfo = ref<Api.Competition.ActivityDetail | null>(null)
  const activityId = ref<number | null>(null)
  const groupId = ref<number | null>(null)
  const teamId = ref<number | null>(null)
  const teamIds = ref<number[]>([])

  function setActivityInfo(info: Api.Competition.ActivityDetail) {
    activityInfo.value = info
    activityId.value = info.Id
  }

  function setActivityId(id: number) {
    activityId.value = id
  }

  function setGroupId(id: number) {
    groupId.value = id
  }

  function setTeamId(id: number) {
    teamId.value = id
  }

  function setTeamIds(ids: number[]) {
    teamIds.value = ids
  }

  function clearActivityInfo() {
    activityInfo.value = null
    activityId.value = null
    groupId.value = null
    teamId.value = null
    teamIds.value = []
  }

  return {
    teamIds,
    activityInfo,
    activityId,
    groupId,
    teamId,
    setActivityInfo,
    setActivityId,
    setGroupId,
    setTeamId,
    setTeamIds,
    clearActivityInfo,
  }
}, {
  persist: true,
})
