import { defineStore } from 'pinia'
import { requestRecentGameList, requestFavoriteGameList, requestOpenGameSearch } from '@/api/game.js'

export const useGameStore = defineStore({
	id: 'game',
	state: () => ({
		favoriteGameList: [],
		// 搜索页数据
		recentSearches: [],
		popularSearches: [],
		hotGameList: [],
		recentGameList: [],
		recommendGameList: []
	}),
	getters: {
		
	},
	actions: {
		async getFavoriteGames () {
			const { code, data } = await requestFavoriteGameList()
			if (code !== 200) { return [] }
			this.favoriteGameList = data || []
			return this.favoriteGameList
		},
		async getRecentGames () {
			const { code, data } = await requestRecentGameList()
			if (code !== 200) { return [] }
			this.recentGameList = data || []
			return this.recentGameList
		},
		async getGameSearchData () {
			const { code, data } = await requestOpenGameSearch()
			if (code === 200 && data) {
				this.recentSearches = data.recentSearches || []
				this.popularSearches = data.popularSearches || []
				this.recentGameList = data.recentGameList || []
				this.hotGameList = data.hotGameList || []
				this.recommendGameList = data.recommendGameList || []
			}
			return true
		},
		// compareIsFavoriteGames (gameList) {
		// 	if (gameList || !gameList.length)
		// }
	}
})