package serializer

import (
	"dsbqj-admin/model/mongo/version"
)

type Version struct {
	Version string `json:"version"`
	Name    string `json:"name"`
	CDN     string `json:"cdn"`
	Url     string `json:"url"`
}

func BuildVersion(version *version.Version) *Version {
	var res *Version
	if version != nil {
		res = &Version{
			Version: version.Version,
			Name:    version.Name,
			CDN:     version.CDN,
			Url:     version.Url,
		}
	}
	return res
}

type Versions map[string]interface{}

func BuildVersions(versions []*version.Version) map[string]interface{} {
	var res Versions = make(map[string]interface{})
	var servers = make([]*Version, 0)
	for _, v := range versions {
		if v.Default {
			res[v.Version] = BuildVersion(v)
		}
		servers = append(servers, BuildVersion(v))
	}
	res["servers"] = servers

	return res
}
