package price_driven

import (
	"github.com/gin-gonic/gin"
	"hongze/hongze_yb/controller/response"
	"hongze/hongze_yb/models/request"
	"hongze/hongze_yb/services/price_driven"
	"hongze/hongze_yb/services/user"
)

// PriceDrivenDetail 价格驱动详情
// @Tags 价格驱动模块
// @Description 获取价格驱动详情
// @Param variety_tag_id  query  int  true  "标签ID"
// @Success 200 {object} response.PriceDrivenItem
// @failure 400 {string} string "获取失败"
// @Router /price_driven/detail [get]
func PriceDrivenDetail(c *gin.Context) {
	var req request.PriceDrivenDetailReq
	if err := c.Bind(&req); err != nil {
		response.Fail("参数有误", c)
		return
	}
	if req.VarietyTagId <= 0 {
		response.Fail("参数有误", c)
		return
	}
	item, errMsg, err := price_driven.GetPriceDrivenDetail(req.VarietyTagId)
	if err != nil {
		response.FailMsg(errMsg, "GetPriceDrivenDetail ErrMsg:"+err.Error(), c)
		return
	}
	response.OkData("获取成功", item, c)
}

// PriceDrivenVisitLog 价格驱动访问记录
// @Tags 价格驱动模块
// @Description 价格驱动访问记录
// @Param price_driven_id	query  int  true  "价格驱动ID"
// @Param source_agent  	query  int  true  "来源"
// @Success 200 {string} string "操作成功"
// @failure 400 {string} string "操作失败"
// @Router /price_driven/visit_log [post]
func PriceDrivenVisitLog(c *gin.Context) {
	var req request.PriceDrivenVisitReq
	if err := c.Bind(&req); err != nil {
		response.Fail("参数有误", c)
		return
	}
	if req.PriceDrivenId <= 0 {
		response.Fail("参数有误", c)
		return
	}
	userInfo := user.GetInfoByClaims(c)
	errMsg, err := price_driven.SavePriceDrivenVisitLog(req.PriceDrivenId, req.SourceAgent, userInfo)
	if err != nil {
		response.FailMsg(errMsg, "PriceDrivenVisitLog ErrMsg:"+err.Error(), c)
		return
	}
	response.Ok("操作成功", c)
}