package router

import (
	"demo/data/dao"
	"github.com/gin-gonic/gin"
	"github.com/spf13/cast"
)

func HomeRouter(engine *gin.RouterGroup) {
	user := engine.Group("/home")
	//user.GET("/search", GetSearchByKey)
	PushRouter(user, "GET", "/banner", GetIndexBanner)
	PushRouter(user, "GET", "/index", GetHomeTopicList)
	PushRouter(user, "GET", "/topic", GetTopicPageList)
	//获取文章详情
	//user.GET("/:id", GetDetailData)
	//PushRouter(user, "GET", "/:id", GetDetailData)
}

// GetIndexBanner 获取首页的banner内容，以及下面相关的内容推荐
func GetIndexBanner(c *gin.Context) {
	data, err := dao.GetAdviceData()
	if err != nil {
		c.JSON(200, CreateResultError(500, "查询错误"))
		return
	}
	c.JSON(200, CreateResultData(data))
}

//获取首页广告内容 ->shop_advice_carousel
//特惠信息 -> 共用轮播图的页面

//设定 首页展示商品 sku数据，topic 添加一个首页显示参数,其次根据排序
//获取商品类型信息 ->goods_type 然后获取到各个商品类型下的商品信息

// GetHomeTopicList 判断topic中的type内容
// sku中的排列为固定排序
func GetHomeTopicList(c *gin.Context) {
	list, err := dao.GetTopicList()
	if err != nil {
		c.JSON(200, CreateResultError(500, "查询错误"))
		return
	}
	//判断同topic
	c.JSON(200, CreateResultData(list))
}

func GetTopicPageList(c *gin.Context) {
	value := c.Query("topicId")
	list, err := dao.GetTopicPageDataListById(cast.ToInt64(value))
	if err != nil {
		c.JSON(200, CreateResultError(500, "查询错误"))
		return
	}
	//判断同topic
	c.JSON(200, CreateResultData(list))
}
