package config

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"log"
)

var ExhibitionConfig struct {
	Styles          map[string][]RoomInfo `json:"styles"`
	PreviewPageSize int                   `json:"preview_page_size"`
	PageSize        int                   `json:"page_size"`
}

type RoomInfo struct {
	Index            int `json:"index"`
	NumberOfPosition int `json:"number_of_position"`
}

func init() {
	data, err := ioutil.ReadFile("./config/exhibition_config.json")
	if err != nil {
		log.Fatalf("加载配置文件失败: %v", err)
	}
	err = json.Unmarshal(data, &ExhibitionConfig)
	if err != nil {
		log.Fatalf("解析配置文件失败: %v", err)
	}
}

func NumberOfPosition(style, roomIndex int) int {
	styleKey := fmt.Sprintf("%d", style)
	rooms, ok := ExhibitionConfig.Styles[styleKey]
	if !ok {
		return 0
	}
	for _, r := range rooms {
		if r.Index == roomIndex {
			return r.NumberOfPosition
		}
	}
	return 0
}
