package conv

/*import (
	"encoding/json"
	"gadmin/package/gmdata"
	"gadmin/utility"
	"github.com/pkg/errors"
	"github.com/sirupsen/logrus"
	"leafstalk/covenant/model"
	"os"
)

var Equipment = new(cEquipment)

type EquipInfo struct {
	BodyId      int    `json:"bodyId"`
	ID          int    `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Star        int    `json:"star"`
	MaxLevel    int    `json:"equiplev"`
	Def         string `json:"def_UP"` // 减伤加成
	Price       int    `json:"price"`
	Skill       []int  `json:"skill"`
	NextSkill   []int  `json:"nextSkill"`

	DecomposeMaterials [][2]int64 `json:"deco_material"`
	Materials          [][2]int64 `json:"material"`
}

type EquipMaterials struct {
	BodyId    int        `json:"bodyId"`
	Level     int        `json:"level"`
	Materials [][2]int64 `json:"material"`
}

type cEquipment struct {
	version string
	radio   float64
	lst     []*gmdata.Equipment
}

func (j *cEquipment) Extract(version string) {
	logrus.Info("cEquipment Extract...")

	// 获取地址：https://demograve.mg.xhgame.com/json/v1.4.9/base_data.json   取值：equipment_disassemble_ratio
	j.radio = float64(1)

	j.setVersion(version).convert()
}

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

func (j *cEquipment) loadJson(fileName string, v interface{}) error {
	b, err := GetUrlBody(j.version, fileName)
	if err != nil {
		return errors.Errorf("loadJson GetUrlBody err:%+v", err)
	}

	if err := json.Unmarshal(b, v); err != nil {
		return errors.Errorf("Unmarshal err=%v", err)
	}

	return nil
}

func (j *cEquipment) convert() *cEquipment {
	typeInfo := map[int]string{1: "weapons.json", 2: "head.json", 3: "body.json", 4: "belt.json", 5: "feet.json", 6: "hand.json"}
	// 武器，穿戴一共6个分类
	allEquipments := make(map[int][]*model.EquipmentAttr)

	// 武器
	var weapons []EquipInfo
	if err := j.loadJson("Weapons.json", &weapons); err != nil {
		panic(err)
	}

	// 装备
	var wears []EquipInfo
	if err := j.loadJson("Wear.json", &wears); err != nil {
		panic(err)
	}

	// 所有装备升级材料
	var updateInfos []EquipMaterials
	if err := j.loadJson("EquipmentMaterials.json", &updateInfos); err != nil {
		panic(err)
	}

	upgradeCategoryMap := map[int][]EquipMaterials{}
	upgradeMap := map[int]EquipMaterials{}

	for _, v := range updateInfos {
		upgradeCategoryMap[v.BodyId] = append(upgradeCategoryMap[v.BodyId], v)
		upgradeMap[v.BodyId*1000+v.Level] = v
	}

	maxStarInfo := map[int]int{}
	for _, v := range weapons {
		if v.ID == 0 {
			continue
		}

		if maxStarInfo[v.BodyId*100+v.ID] < v.Star {
			maxStarInfo[v.BodyId*100+v.ID] = v.Star
		}
	}
	for _, v := range wears {
		if v.ID == 0 {
			continue
		}
		if maxStarInfo[v.BodyId*100+v.ID] < v.Star {
			maxStarInfo[v.BodyId*100+v.ID] = v.Star
		}
	}

	infos := append(weapons, wears...)
	for _, v := range infos { // 所有装备进行遍历
		for ilevel := 1; ilevel <= v.MaxLevel; ilevel++ {

			pId := v.BodyId
			// if v.BodyId == 2 {
			// 	pId = 3
			// } else if v.BodyId == 3 {
			// 	pId = 2
			// }
			item := &model.EquipmentAttr{
				ID:   int64(pId*10_000_000 + v.ID*100_000 + v.Star*1_000 + ilevel),
				Star: v.Star,
				//Level:    uint(ilevel),
				//Material: v.ID,
				//WearPart: v.BodyId,
				Price: v.Price,
				Name:  v.Name,
			}

			if item.Star < maxStarInfo[pId*100+v.ID] {
				item.NextStar = int64(pId*10_000_000 + v.ID*100_000 + (v.Star+1)*1_000 + ilevel)
			}
			//if item.Level < uint(v.MaxLevel) {
			//	item.NextLevel = int64(pId*10_000_000 + v.ID*100_000 + (v.Star)*1_000 + ilevel + 1)
			//}
			//if item.Level > 1 {
			//	upgradeInfo := upgradeMap[v.BodyId*1000+int(item.Level)]
			//	for _, v2 := range upgradeInfo.Materials {
			//		item.Cost = append(item.Cost, &model.DropMaterial{ID: v2[0], Count: v2[1]})
			//	}
			//} else {
			//	if item.Level == 1 {
			//		for _, v2 := range v.DecomposeMaterials {
			//			item.Cost = append(item.Cost, &model.DropMaterial{ID: v2[0], Count: v2[1]})
			//		}
			//	}
			//}

			extraInfo := map[int64]int64{}
			//for _, v2 := range upgradeCategoryMap[v.BodyId] {
			//	if v2.Level <= int(item.Level) {
			//		for _, v3 := range v2.Materials {
			//			extraInfo[v3[0]] += v3[1]
			//		}
			//	}
			//}

			//radio
			for k, v := range extraInfo {
				extraInfo[k] = int64(float64(v) * j.radio)
			}

			for _, v2 := range v.DecomposeMaterials {
				extraInfo[v2[0]] += v2[1]
			}

			for k, v2 := range extraInfo {
				item.Extract = append(item.Extract, &model.DropMaterial{ID: k, Count: int(v2)})
			}
			if item.Extract[0].ID != 1001 {
				item.Extract[0], item.Extract[1] = item.Extract[1], item.Extract[0]
			}

			allEquipments[v.BodyId] = append(allEquipments[v.BodyId], item)
		}
	}

	for k, v := range typeInfo {
		filePath2 := utility.LocalJsonPath(j.version, v)
		logrus.Print("Equipment convert filePath2:"+filePath2, "\r\n")
		equipFile2, err := os.Create(filePath2)
		if err != nil {
			logrus.Errorln("写日志文件失败", err)
		}

		encoder := json.NewEncoder(equipFile2)
		var data []*model.EquipmentAttr
		for _, v := range allEquipments[k] {
			data = append(data, v)
		}

		if err = encoder.Encode(data); err != nil {
			logrus.Infoln("Encoder failed", err.Error())

		} else {
			logrus.Infoln("Encoder success")
		}
		equipFile2.Close()
	}
	return j
}*/
