package web

import (
	"github.com/gin-gonic/gin"
	"goskeleton/app/global/consts"
	"goskeleton/app/service/ai_model_cli"
	"goskeleton/app/utils/response"
)

type StyleGenerate struct {
}
type LayoutGenerate struct {
}

// ai生成样式
func (s *StyleGenerate) StyleGenerate(c *gin.Context) {
	// 非流式传输
	// if res, err := ai_model_cli.RequestStyle(c); err==nil {
	// 	response.Success(c, consts.CurdStatusOkMsg, res.(string))
	// } else {
	// 	response.Fail(c, consts.StyleGenerateFailCode, consts.StyleGenerateFailMsg, err)
	// }

	// 设置 HTTP 头部为 SSE
	c.Writer.Header().Set("Content-Type", "text/event-stream")
	c.Writer.Header().Set("Cache-Control", "no-cache")
	c.Writer.Header().Set("Connection", "keep-alive")

	if err := ai_model_cli.RequestStyleStream(c); err != nil {
		response.Fail(c, consts.StyleGenerateFailCode, consts.StyleGenerateFailMsg, err)
	}

}

// ai排版
func (l *LayoutGenerate) LayoutGenerate(c *gin.Context) {
	// 流式传输
	// 设置 HTTP 头部为 SSE
	c.Writer.Header().Set("Content-Type", "text/event-stream")
	c.Writer.Header().Set("Cache-Control", "no-cache")
	c.Writer.Header().Set("Connection", "keep-alive")
	if err := ai_model_cli.RequestLayout(c); err != nil {
		response.Fail(c, consts.LayoutGenerateFailCode, consts.LayoutGenerateFailMsg, err)
	}
}
