import { store } from '@/store'
import { defineStore } from 'pinia'

interface EventNotify {
  id?: string // 事件ID
  eventType?: string // 事件类型(对应EVENT_TYPES)
  eventStartTime?: string // 事件开始时间
  eventEndTime?: string // 事件结束时间
  eventCarPlate?: string // 车牌号
  eventSituation?: string // 事件描述
  eventStatus?: number // 事件状态(对应EVENT_STATUS)
}

interface TrafficType {
  waves: string[] // 标注车辆，事件相关等
  nowEvents: any[] // 当前事件标注
  oldEvents: any[] // 回溯事件标注
  eventCount: number // 事件数量
  eventNotify: EventNotify | null // 事件通知
}

export const useTrafficStore = defineStore('traffic', {
  state: (): TrafficType => ({
    waves: [],
    nowEvents: [],
    oldEvents: [],
    eventCount: 0,
    eventNotify: null
  }),
  getters: {
    getWaves() {
      return this.waves
    },

    getNowEvents() {
      return this.nowEvents
    },

    getOldEvents() {
      return this.oldEvents
    },

    getEventCount() {
      return this.eventCount
    },

    getEventNotify() {
      return this.eventNotify
    }
  },

  actions: {
    setWaves(e) {
      this.waves = e || []
    },

    setNowEvents(e) {
      this.nowEvents = e || []
    },

    setOldEvents(e) {
      this.oldEvents = e || []
    },

    setEventCount(e) {
      this.eventCount = e || 0
    },

    setEventNotify(e) {
      this.eventNotify = e || null
    }
  }
})

export const useTrafficStoreOut = () => {
  return useTrafficStore(store)
}
