import { defineStore } from 'pinia'
import { requestMailList } from '@/api/mail.js'

export const useMailStore = defineStore({
	id: 'mail',
	state: () => ({
		hasUnread: false,
		mailList: [],
	}),
	getters: {
		
	},
	actions: {
		async getMailList () {
			const { code, data } = await requestMailList()
			if (code !== 200) { return [] }
			const list = data || []
			let flag = false
			list.forEach(el => {
				if (!el.isRead) {
					flag = true
				}
			})
			this.mailList = list
			this.hasUnread = flag
			return list
		}
	}
})
