package maker

import (
	"context"
	"path/filepath"

	"gitea.loveuer.com/yizhisec/pkg3/logger"
	"yizhisec.com/hsv2/forge/internal/opt"
	"yizhisec.com/hsv2/forge/pkg/archiver"
)

func (m *maker) Binary(ctx context.Context) error {
	var (
		tarURL = "https://artifactory.yizhisec.com:443/artifactory/filestore/hsv3/k8s-bin.tar"
		binDir = filepath.Join(opt.Cfg.Make.Dir, "dependency")
	)

	logger.Info("☑️ 开始准备 k8s 二进制文件...")
	logger.Debug("下载地址: %s", tarURL)
	logger.Debug("目标目录: %s", binDir)

	if err := archiver.DownloadAndExtract(
		ctx,
		tarURL,
		binDir,
		archiver.WithInsecureSkipVerify(),
		archiver.WithGzipCompression(true),
	); err != nil {
		logger.Info("❌ 下载并解压二进制文件失败")
		return err
	}

	logger.Info("✅ 准备 k8s 二进制文件成功!!!")

	return nil
}
