import { defineStore } from 'pinia'

export type AuditLogItem = {
  id: string
  actor: string
  action: string
  resource: string
  createdAt: string
}

export const useAuditStore = defineStore('audit', {
  state: () => ({
    items: [] as AuditLogItem[]
  }),
  actions: {
    init(items: AuditLogItem[]) {
      if (this.items.length) return
      this.items = items
    },
    addLog(action: string, resource: string, actor: string = '演示管理员') {
      this.items.unshift({
        id: `audit-${Date.now()}`,
        actor,
        action,
        resource,
        createdAt: new Date().toISOString()
      })
    }
  }
})
