package main

import (
	"encoding/json"
	"fmt"
	"math/rand/v2"
	"os"
)

var Cards = []struct {
	lane     Lane
	typ      Type
	entropy  int
	recovery int
	force    int
	name     string
	desc     string
}{
	{typ: Passive, recovery: 3,
		name: `Rapid Response`, desc: `Your {{spell}}s cost {{1 hp}} less.`},
	{typ: Passive, recovery: 2,
		name: `Breaker`, desc: `The first {{unit}} you play per turn costs {{1 entropy}} less.`},
	{typ: Passive, recovery: 0,
		name: `Inverse Entropy`, desc: `Add {{1 hp}} to all {{lifesteal}} bonuses`},
}

type Lane int

const (
	Any Lane = iota
	Red
	Green
	Blue
)

type Type int

const (
	Unit Type = iota
	Spell
	Passive
	Token
)

func (l Lane) String() string {
	switch l {
	case Any:
		return "⬜ Any"
	case Red:
		return "🟥 Red"
	case Green:
		return "🟩 Green"
	case Blue:
		return "🟦 Blue"
	default:
		panic("unknwon")
	}
}

func (t Type) String() string {
	switch t {
	case Unit:
		return "Unit"
	case Passive:
		return "Passive"
	case Token:
		return "Token"
	default:
		panic("unknown")
	}
}

func main() {
	type (
		jsonfront struct {
			Name       string `json:"name"`
			Type       string `json:"type"`
			Cost       int    `json:"cost"`
			Image      string `json:"image"`
			Horizontal bool   `json:"isHorizontal"`
		}
		jsoncard struct {
			// required
			Id   string `json:"id"`
			Face struct {
				Front jsonfront `json:"front"`
			} `json:"face"`
			Name  string `json:"name"`
			Type  string `json:"type"`
			Cost  int    `json:"cost"`
			Token bool   `json:"isToken"`

			// custom
			Lane    string `json:"Lane"`
			Entropy int    `json:"Entropy"`
			Force   int    `json:"Force"`
			Legal   bool   `json:"_legal"`
		}
	)

	thejson := make(map[string]jsoncard)
	for i := range len(Cards) {
		card := &Cards[i]
		if len(card.name) == 0 {
			card.name = generateTemporaryName()
		}

		var imgurl string
		switch card.lane {
		case Red:
			imgurl = "https://media.discordapp.net/attachments/1093017032812929024/1489047949337038959/red-base.png?ex=69ceff78&is=69cdadf8&hm=7d2ba991862426bf6fe97f9ccbb0c8c60e6dd5e3c7d32f2a8e206130aad3c37e&=&format=webp&quality=lossless&width=2078&height=1488"
		case Blue:
			imgurl = "https://media.discordapp.net/attachments/1093017032812929024/1489047948531597432/blue-base.png?ex=69ceff78&is=69cdadf8&hm=4cf2d26b195780d4d044702d51f2d6423034978f1245cf49e4b43ea5f998632e&=&format=webp&quality=lossless&width=2078&height=1488"
		case Green:
			imgurl = "https://media.discordapp.net/attachments/1093017032812929024/1489047948959547483/green-base.png?ex=69ceff78&is=69cdadf8&hm=ffb7d13f9c86bf501b22cf8121f88cf1dd49b3696ef92ba6655934f61cae7448&=&format=webp&quality=lossless&width=2078&height=1488"
		default:
			imgurl = "https://media.discordapp.net/attachments/1093017032812929024/1489048592743141426/passive-base.png?ex=69cf0011&is=69cdae91&hm=9e673eb63e15f33d7b5579596b247e1832ccc76bee59477602fa6fd8cc544d73&=&format=webp&quality=lossless&width=2078&height=1488"
		}

		id := fmt.Sprintf("%03d", i)
		thejson[id] = jsoncard{
			Id: id,
			Face: struct {
				Front jsonfront `json:"front"`
			}{
				jsonfront{
					Name:       card.name,
					Type:       card.typ.String(),
					Image:      imgurl,
					Cost:       card.entropy,
					Horizontal: true,
				},
			},
			Token: card.typ == Token,
			Name:  card.name,
			Type:  card.typ.String(),
			Cost:  card.entropy,

			Entropy: card.entropy,
			Force:   card.force,
			Lane:    card.lane.String(),
			Legal:   true,
		}
	}

	enc, err := json.MarshalIndent(thejson, "", "  ")
	if err != nil {
		panic(err)
	}

	if err := os.WriteFile("docs/CardList.json", enc, 0644); err != nil {
		panic(err)
	}
}

func generateTemporaryName() string {
	var (
		adjectives = []string{
			"Absent",
			"Ambient",
			"Bare",
			"Blunt",
			"Civic",
			"Composite",
			"Concave",
			"Dull",
			"Errant",
			"Excess",
			"Flat",
			"Former",
			"Gross",
			"Inland",
			"Lateral",
			"Live",
			"Lucid",
			"Moot",
			"Nominal",
			"Oblique",
			"Partial",
			"Passive",
			"Petit",
			"Polar",
			"Residual",
			"Rote",
			"Soft",
			"Spent",
			"Terminal",
			"Warm",
		}
		nouns = []string{
			"Aperture",
			"Axis",
			"Bulk",
			"Cartilage",
			"Compact",
			"Contour",
			"Conviction",
			"Cortex",
			"Deficit",
			"Dividend",
			"Dosage",
			"Envelope",
			"Filament",
			"Gesture",
			"Gradient",
			"Inlet",
			"Lapse",
			"Mandate",
			"Membrane",
			"Morale",
			"Offset",
			"Posture",
			"Precinct",
			"Prospect",
			"Rapport",
			"Reflex",
			"Substrate",
			"Surplus",
			"Tendon",
			"Volume",
		}
	)

	return adjectives[rand.IntN(len(adjectives))] + nouns[rand.IntN(len(nouns))]
}
