package main

import (
	"encoding/json"
	"lc/common/configor"
	"lc/common/protocol"
	"lc/common/util"
	"strings"
)

type DevConfig struct {
	LedInfos *[]LedInfo `json:"dev"`
}

// led屏配置
type LedInfo struct {
	Id      int    `json:"id"`
	Name    string `json:"name"`    //名字
	DevCode string `json:"devCode"` //区分是什么设备
	Brand   string `json:"brand"`   //品牌
	Model   string `json:"model"`   //型号
	SN      string `json:"sn"`
	IP      string `json:"ip"`
	BaseURL string `json:"baseurl"`
}

func GetTopic(sn, downORup string) string {
	return appConfig.Tenant + "/cltled/" + sn + "/" + downORup + "/#"
}
func getUpTopic(topic string) string {
	return strings.Replace(topic, "down", "up", 1)
}

var appConfig protocol.AppConfig

var ledInfos []LedInfo

func GetListError(errstr string) []byte {
	marshal, _ := json.Marshal(`{"error": "查询失败"}`)
	return marshal
}

func loadAppConfig() error {
	var o protocol.AppConfig
	err := configor.Load(&o, util.GetPath(0)+"app.json")
	if err == nil && o.GID != "" {
		appConfig = o
	}
	return err
}

func loadDevInfos() {
	var devConfig = DevConfig{
		&ledInfos,
	}
	path := util.GetPath(0) + "led.json"
	configor.Load(&devConfig, path)
}
