package swagger

import (
	"testing"

	"github.com/zeromicro/go-zero/tools/goctl/api/spec"
)

type Context struct {
	Api                    *spec.ApiSpec // API 規範，用於查找類型定義
	UseDefinitions         bool
	WrapCodeMsg            bool
	BizCodeEnumDescription string
}

func testingContext(_ *testing.T) Context {
	return Context{}
}

func contextFromApi(api *spec.ApiSpec) Context {
	if len(api.Info.Properties) == 0 {
		return Context{
			Api: api,
		}
	}
	return Context{
		Api:                    api,
		UseDefinitions:         getBoolFromKVOrDefault(api.Info.Properties, propertyKeyUseDefinitions, defaultValueOfPropertyUseDefinition),
		WrapCodeMsg:            getBoolFromKVOrDefault(api.Info.Properties, propertyKeyWrapCodeMsg, false),
		BizCodeEnumDescription: getStringFromKVOrDefault(api.Info.Properties, propertyKeyBizCodeEnumDescription, "business code"),
	}
}
