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) Deb(ctx context.Context) error {
	var (
		tarURL = "https://artifactory.yizhisec.com:443/artifactory/filestore/hsv3/deb/docker.tar.gz"
		binDir = filepath.Join(opt.Cfg.Make.Dir, "dependency", "deb")
	)

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

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

	logger.Info("✅ 准备 deb(docker) 文件成功!!!")
	return nil

}
