package backend

import (
	"strconv"
	"strings"
)

// masterySpecializationRootHexes comes from the unpacked 2.0.2
// table/skillboard_layout.tbl. In the fixed 140-byte layout rows, every R2/R3
// direction has exactly one 100-MSP root; all 1,392 ordinary R2/R3 sub-trait
// rows cost 50 MSP. The table contains 29 characters × 3 directions × 2
// stages = 174 specialization roots. Keeping the audited hashes explicit lets
// the editor distinguish the unlabelled roots without guessing from text.
const masterySpecializationRootHexes = `
037264AD 03EC4163 04B8460F 052877D6 0543859F 05C55C03
05C627B1 097EB3D2 0AF99EFF 0B04EF3C 0B2BDE7C 0D65A2FC
0EBEE35E 0FB171F0 107F5935 14994527 16536B74 16D3B6E1
180AABFD 1CE57BDF 24CFE8D4 26065BA8 278FAC92 29108696
2AF3E746 2B579404 306B1CD4 3183E207 3255D31E 32868476
33876E12 34D818D1 373F42CB 3A77839A 3A9FDE00 3B559BDD
3E375363 3F18C4C3 3FFBA9FC 43D18E34 49E65B86 49F7A23A
4BB6BC6C 4C6C25FA 4CDB9190 515F74DB 51B99B73 53BE2200
53F90323 55618F11 56F540AA 58E2FE10 5A496593 5A71648E
5C3AB770 5EC731D0 6083BF30 61DF8146 61DF9298 61E85EEF
62146473 64C5A394 6877356B 693F9A3D 699ED629 6A815E89
6E6712DE 70295B88 708F61B9 783CF456 7A074115 7C50D4D0
7D001159 7D0726E5 7EEC403D 80490676 812BE389 813C8A68
813DCC57 81F4970A 82E8AED8 83A4DA1F 84359F89 84A139B4
88DCAC00 8A1BAC43 8EE7C8E3 900AA82F 93392537 9436084C
9453182C 9495DA95 95618B62 957C28B0 9633CA4E 991BCF45
9B18FDE4 9B594D45 9BBF6638 9C64B13A 9D8321D0 9DB37638
9E8DEB77 9ED8CAF8 A14215F4 A4AE3A88 A4B02EE5 A4E80A7F
A66FF5E8 A6B09B4B A907C7EF AB8A1972 AC2CF80E AD015C43
B034603C B067726F B0D7B5F9 B106CD9F B19401AF B2949EF8
B7AE96CD B9008851 BB569652 BCB74C00 BE014909 BE12FBD4
BEEDAA97 BF9AE6FC BFF2CE5F C2CC0608 C37A70E5 C6C436F4
C810806A C87694AF CA15C44C CB622EB6 CB99AA1A D02CDC78
D11ABA39 D21CFB37 D34B1BD5 D50884D3 D58614BF D74C2294
D788CD2F D87C9161 D8CCF507 D92F6279 DBFC0713 DCA5232B
DD09F461 E0A933AD E0C14CDB E3297BA7 E33A48E3 E406C706
E5BAAA44 E63217E6 E793271E E7F0CA6C E83E6E2D E8FF0E68
EAE7DE02 EB506CA1 ECB717F4 F09B2EC9 F100DD36 F25A18E6
F41B489D F6D96870 F7DCAB0B F95E9E93 FA98716F FFC5E3DE
`

var masterySpecializationRoots = func() map[uint32]struct{} {
	result := make(map[uint32]struct{}, 174)
	for _, value := range strings.Fields(masterySpecializationRootHexes) {
		parsed, err := strconv.ParseUint(value, 16, 32)
		if err != nil {
			panic("invalid audited mastery specialization root: " + value)
		}
		result[uint32(parsed)] = struct{}{}
	}
	return result
}()

func isMasterySpecializationHash(hash uint32) bool {
	_, ok := masterySpecializationRoots[hash]
	return ok
}
