package view

import (
	"git.lxtend.com/lixiangwuxian/qqbot/handler/blackjack/controller"
	"git.lxtend.com/lixiangwuxian/qqbot/handler/blackjack/model"
)

func getEmojiOfColor(color string) string {
	switch color {
	case "Spade":
		return "♠"
	case "Heart":
		return "♥️"
	case "Diamond":
		return "♦"
	case "Club":
		return "♣"
	default:
		return ""
	}
}

type LiteralViewer struct {
	response  string
	simulator *controller.BackJackSimulator
}

func NewLiteralViewer(simulator *controller.BackJackSimulator) *LiteralViewer {
	return &LiteralViewer{
		simulator: simulator,
		response:  "",
	}
}

func generateCardSeries(deck *model.Deck) string {
	cards := ""
	for _, card := range deck.Cards() {
		if card.Visible {
			cards += getEmojiOfColor(card.Color) + card.Name + " "
		} else {
			cards += "🂠 "
		}
	}
	return cards
}

func (viewer *LiteralViewer) GetResponse() string {
	viewer.response = ""
	viewer.response += "[🃏] Dealer: " + generateCardSeries(viewer.simulator.GetDealerCards()) + "\n"
	viewer.response += "[🎴] Player: " + generateCardSeries(viewer.simulator.GetPlayerCards()) + "\n"
	return viewer.response
}
