/*
 * Copyright 2023 CloudWeGo Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Code generated by hertz generator.

package publish

import (
	"context"

	"github.com/cloudwego/hertz/pkg/app"
	"github.com/cloudwego/hertz/pkg/protocol/consts"

	publish "github.com/cloudwego/hertz-examples/bizdemo/tiktok_demo/biz/model/basic/publish"
	service "github.com/cloudwego/hertz-examples/bizdemo/tiktok_demo/biz/service/publish"
	"github.com/cloudwego/hertz-examples/bizdemo/tiktok_demo/pkg/errno"
	"github.com/cloudwego/hertz-examples/bizdemo/tiktok_demo/pkg/utils"
)

// PublishAction publish a video
//
// @router /douyin/publish/action/ [POST]
func PublishAction(ctx context.Context, c *app.RequestContext) {
	var err error

	var req publish.DouyinPublishActionRequest
	err = c.BindAndValidate(&req)
	if err != nil {
		resp := utils.BuildBaseResp(errno.ParamErr)
		c.JSON(consts.StatusBadRequest, publish.DouyinPublishActionResponse{
			StatusCode: resp.StatusCode,
			StatusMsg:  resp.StatusMsg,
		})
		return
	}
	err = service.NewPublishService(ctx, c).PublishAction(&req)

	resp := utils.BuildBaseResp(err)
	c.JSON(consts.StatusOK, publish.DouyinPublishActionResponse{
		StatusMsg:  resp.StatusMsg,
		StatusCode: resp.StatusCode,
	})
}

// PublishList get the video list of user
//
// @router /douyin/publish/list/ [GET]
func PublishList(ctx context.Context, c *app.RequestContext) {
	var err error
	var req publish.DouyinPublishListRequest
	err = c.BindAndValidate(&req)
	if err != nil {
		c.String(consts.StatusBadRequest, err.Error())
		return
	}

	resp, err := service.NewPublishService(ctx, c).PublishList(&req)
	if err != nil {
		bresp := utils.BuildBaseResp(err)
		resp.StatusCode = bresp.StatusCode
		resp.StatusMsg = bresp.StatusMsg
		c.JSON(consts.StatusOK, resp)
	}
	resp.StatusCode = errno.SuccessCode
	resp.StatusMsg = errno.SuccessMsg
	c.JSON(consts.StatusOK, resp)
}
