package community

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

// VideoList 视频列表
// @Tags 视频社区模块
// @Description 获取视频社区列表
// @Param page_index			query int false "页码"
// @Param page_size				query int false "每页数量"
// @Param keywords				query string false "只看我的"
// @Param video_id				query int false "视频ID"
// @Param variety_tag_id		query int false "标签ID"
// @Success 200 {object}
// @failure 400 {string} string "获取失败"
// @Router /video/list [get]
func VideoList(c *gin.Context) {
	var req request.VideoListReq
	if err := c.Bind(&req); err != nil {
		response.Fail("参数有误", c)
		return
	}
	if req.PageIndex == 0 {
		req.PageIndex = 1
	}
	if req.PageSize == 0 {
		req.PageSize = utils.PageSize20
	}
	list, err := community.GetVideoList(req.PageIndex, req.PageSize, req.VideoId, req.VarietyTagId, req.Keywords)
	if err != nil {
		response.FailMsg("获取失败", "VideoList ErrMsg:"+err.Error(), c)
		return
	}
	response.OkData("获取成功", list, c)
}

// VideoPlayLog 记录视频播放日志
// @Tags 视频社区模块
// @Description 记录视频播放日志
// @Param video_id		query  int  true  "音频ID"
// @Param source_agent	query  int  true  "操作来源，1：小程序，2：小程序 pc 3:弘则研究公众号，4:web pc"
// @Success 200 {string} string "操作成功"
// @failure 400 {string} string "操作失败"
// @Router /video/play_log [post]
func VideoPlayLog(c *gin.Context) {
	var req request.VideoPlayLogReq
	if err := c.ShouldBind(&req); err != nil {
		response.Fail("参数有误", c)
		return
	}
	if req.VideoId == 0 {
		response.Fail("参数有误", c)
		return
	}
	if req.SourceAgent == 0 {
		response.Fail("参数有误", c)
		return
	}
	userinfo := user.GetInfoByClaims(c)
	errMsg, err := community.SaveVideoPlayLog(userinfo, req.VideoId, req.SourceAgent)
	if err != nil {
		response.FailMsg(errMsg, "VideoPlayLog ErrMsg:"+err.Error(), c)
		return
	}
	response.Ok("操作成功", c)
}
