package ai_layout
import(
	"github.com/gin-gonic/gin"
	"goskeleton/app/utils/response"
	"goskeleton/app/http/controller/web"
	"goskeleton/app/http/validator/core/data_transfer"
	"goskeleton/app/global/consts"
)
type ChatRecord struct {
    Role    string `json:"role" binding:"required"`
    Content string `json:"content" binding:"required"`
}

type StyleGenerate struct {
    UserInput   string       `form:"user_input" json:"user_input" binding:"required"` // 必填
    ChatHistory []ChatRecord `form:"char_history" json:"chat_history"`				  // 非必填
}

func (s StyleGenerate) CheckParams(context *gin.Context) {
	// 将表单参数验证器出现的错误直接交给错误翻译器统一处理即可
	if err := context.ShouldBind(&s); err != nil {
		response.ValidatorError(context, err)
		return
	}
	//  该函数主要是将本结构体的字段（成员）按照 consts.ValidatorPrefix+ json标签对应的 键 => 值 形式绑定在上下文，便于下一步（控制器）可以直接通过 context.Get(键) 获取相关值
	extraAddBindDataContext := data_transfer.DataAddContext(s, consts.ValidatorPrefix, context)
	if extraAddBindDataContext == nil {
		response.ErrorSystem(context, "StyleGenerate表单参数验证器json化失败", "")
		return
	}
	(&web.StyleGenerate{}).StyleGenerate(extraAddBindDataContext)
}