package conv

import (
	"gadmin/package/gmdata"
	"gadmin/utility"
	"github.com/sirupsen/logrus"
)

var GrandMaster = new(cGrandMaster)

type cGrandMaster struct {
	version string
	lst     []*gmdata.Role
}

func (j *cGrandMaster) Extract(version string) {
	logrus.Info("cGrandMaster Extract...")
	j.setVersion(version).save()
}

func (j *cGrandMaster) setVersion(version string) *cGrandMaster {
	j.version = version
	return j
}

func (j *cGrandMaster) save() {
	// 下载的文件列表
	downs := []string{"KingSeasonDan.json"}
	for _, fileName := range downs {

		// 保存文件
		url := utility.PullJsonAddr(j.version, fileName)
		dstFileName := utility.LocalJsonPath(j.version, fileName)
		if err := HttpRequestToFile(url, dstFileName); err != nil {
			logrus.Info("HttpRequestToFile err:%+v", err)
			return
		}
	}
}
