package maker

import (
	"context"
	"os"
	"path/filepath"

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

func (m *maker) LessDNS(ctx context.Context) error {
	var (
		err      error
		location = filepath.Join(opt.Cfg.Make.Dir, "dependency", "less-dns")
	)

	logger.Info("MakeLessDNS: 开始构建 less-dns...")
	if err = os.MkdirAll(location, 0755); err != nil {
		logger.Error("MakeLessDNS: 创建目录失败s")
		logger.Debug("MakeLessDNS: 创建目录失败: %s", err.Error())
		return err
	}

	if err = os.WriteFile(filepath.Join(location, "deployment.yaml"), resource.YAMLLessDNS, 0644); err != nil {
		logger.Error("MakeLessDNS: 写入文件失败")
		logger.Debug("MakeLessDNS: 写入文件失败: %s", err.Error())
		return err
	}

	logger.Info("MakeLessDNS: 构建 less-dns 成功!!!")
	return nil
}
