import { ref } from 'vue'
import { defineStore } from 'pinia'
import type { Message, UserInfo } from '@/types/global'

export const useMessageStore = defineStore('message', () => {
  const messageRecords = ref<Message[]>([])
  const setMessageRecord = (record: Message) => {
    messageRecords.value.push(record)
  }
  const getMessageRecord = (userId: any) => {
    return messageRecords.value || []
  }
  const removeMessageRecord = (record: Message) => {
    messageRecords.value = messageRecords.value.filter(item => item.id !== record.id)
  }
  return { messageRecords, setMessageRecord, getMessageRecord, removeMessageRecord }
})


export const usePendingMessageStore = defineStore('pendingMessage', () => {
  const messageRecords = ref<Message[]>([])
  const setMessageRecord = (record: Message) => {
    messageRecords.value.push(record)
  }
  const getMessageRecord = () => {
    return messageRecords.value || []
  }
  const removeMessageRecord = (record: Message) => {
    messageRecords.value = messageRecords.value.filter(item => item.id !== record.id)
  }
  return { messageRecords, setMessageRecord, getMessageRecord, removeMessageRecord }
})

export const useUserInfoStore = defineStore('userInfo', () => {
  const userInfo = ref({} as UserInfo)
  const setUserInfo = (newUserInfo: UserInfo) => {
    userInfo.value = newUserInfo
  }
  const getUserInfo = () => {
    return userInfo.value || {}
  }
  return { userInfo, setUserInfo, getUserInfo }
})
