package appservice

import (
	adminservice "go-admin/app/admin/service"
	"go-admin/app/admin/service/dto"
	statuscode "go-admin/common/status_code"
	"go-admin/pkg/utility"

	"github.com/go-admin-team/go-admin-core/sdk/service"
)

type Common struct {
	service.Service
}

// 获取前端 默认设置
func (e *Common) GetDefaultSet() (dto.FrontedDefaultSetResp, int) {
	result := dto.FrontedDefaultSetResp{}
	keys := []string{"control_telegram_link", "control_customer_service", "control_binance_referral", "member_min_order_amount"}
	configService := adminservice.SysConfig{Service: e.Service}
	configMaps := make(map[string]dto.GetSysConfigByKEYForServiceResp)
	configService.GetWithKeys(&keys, &configMaps)

	if config, ok := configMaps["control_telegram_link"]; ok {
		result.TelegramLink = config.ConfigValue
	}

	if config, ok := configMaps["control_customer_service"]; ok {
		result.CustomServiceLink = config.ConfigValue
	}

	if config, ok := configMaps["control_binance_referral"]; ok {
		result.BinanceReferralLink = config.ConfigValue

		params, _ := utility.ParseURLParams(result.BinanceReferralLink)

		if code, ok := params["ref"]; ok {
			result.BinanceReferralCode = code
		}
	}

	if config, ok := configMaps["member_min_order_amount"]; ok {
		result.MinOrderAmount = config.ConfigValue
	}

	return result, statuscode.OK
}
