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) EMQX(ctx context.Context) error {
	var (
		err      error
		location = filepath.Join(opt.Cfg.Make.Dir, "emqx")
	)

	logger.Info("☑️ MakeEMQX: 开始构建 emqx(mqtt) 依赖...")

	if err = os.MkdirAll(location, 0755); err != nil {
		logger.Debug("❌ MakeEMQX: 创建 emqx 目录失败: %v", err)
		return err
	}

	if err = os.WriteFile(filepath.Join(location, "emqx.yaml"), resource.YAMLEMQX, 0644); err != nil {
		logger.Debug("❌ MakeEMQX: 写入 emqx.yaml 失败, err: %v", err)
		return err
	}

	logger.Info("✅ MakeEMQX: 构建 emqx(mqtt) 依赖成功!!!")
	return nil
}
