package gmdata

import (
	"encoding/json"
	"fmt"
	"testing"
)

func TestShopJson(t *testing.T) {
	type Item struct {
		ID        int `json:"ID"`
		Materials []struct {
			ID    int `json:"id"`
			Count int `json:"count"`
		} `json:"Materials"`
		Equipments []int       `json:"Equipments"`
		Gift       interface{} `json:"Gift"`
		Cost       []struct {
			ID    int `json:"id"`
			Count int `json:"count"`
		} `json:"Cost"`
		OtherGoods  interface{} `json:"OtherGoods"`
		AdCoolDown  int         `json:"AdCoolDown"`
		AdDayTimes  int         `json:"AdDayTimes"`
		TotalTimes  int         `json:"TotalTimes"`
		FirstDouble int         `json:"FirstDouble"`
		GoodsType   int         `json:"GoodsType"`
		StartTime   int         `json:"StartTime"`
		EndTime     int         `json:"EndTime"`
		OpenLevel   int         `json:"OpenLevel"`
		MaxLevel    int         `json:"MaxLevel"`
	}

	jsonData := `{
		"1": {
			"ID": 1,
			"Materials": null,
			"Equipments": null,
			"Gift": null,
			"Cost": [{
				"id": 1012,
				"count": 1
			}],
			"OtherGoods": null,
			"AdCoolDown": 0,
			"AdDayTimes": 0,
			"TotalTimes": 0,
			"FirstDouble": 0,
			"GoodsType": 1,
			"StartTime": 0,
			"EndTime": 0,
			"OpenLevel": 0,
			"MaxLevel": 1000000
		},
		"10": {
			"ID": 10,
			"Materials": [{
					"id": 1001,
					"count": 20000
				},
				{
					"id": 1002,
					"count": 600
				},
				{
					"id": 6005,
					"count": 20
				}
			],
			"Equipments": [50104001],
			"Gift": null,
			"Cost": [{
				"id": 0,
				"count": 6
			}],
			"OtherGoods": null,
			"AdCoolDown": 300,
			"AdDayTimes": 0,
			"TotalTimes": 0,
			"FirstDouble": 0,
			"GoodsType": 6,
			"StartTime": 0,
			"EndTime": 0,
			"OpenLevel": 0,
			"MaxLevel": 1000000
		}
	}`

	var data map[string]Item
	err := json.Unmarshal([]byte(jsonData), &data)
	if err != nil {
		fmt.Println("Unmarshal error:", err)
		return
	}

	// 遍历解析后的数据
	for key, value := range data {
		fmt.Printf("Key: %s\n", key)
		fmt.Printf("ID: %d\n", value.ID)
		fmt.Printf("Materials: %v\n", value.Materials)
		fmt.Printf("Equipments: %v\n", value.Equipments)
		fmt.Printf("Cost: %v\n", value.Cost)
		// ... 解析其他字段
		fmt.Println("--------------------")
	}

}
