package bundle

import (
	"context"
	"fmt"
	"fonchain-fiee/api/bundle"
	"fonchain-fiee/pkg/model/login"
	"fonchain-fiee/pkg/service"

	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
)

func CreateValueAddBundle(c *gin.Context) {
	var req bundle.CreateValueAddBundleRequest

	if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
		service.Error1(c, err)
		return
	}

	res, err := service.BundleProvider.CreateValueAddBundle(context.Background(), &req)
	if err != nil {
		fmt.Println(err)
		service.Error1(c, err)
		return
	}

	service.Success1(c, res.Msg, res)
}

func ValueAddBundleList(c *gin.Context) {
	var req bundle.ValueAddBundleListRequest

	if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
		service.Error1(c, err)
		return
	}

	// 获取 用户信息
	userInfo := login.GetUserInfoFromC(c)
	req.UserId = int32(userInfo.ID)
	//req.UserId = 39

	res, err := service.BundleProvider.ValueAddBundleList(context.Background(), &req)
	if err != nil {
		service.Error1(c, err)
		return
	}

	service.Success1(c, res.Msg, res)
}

func ValueAddBundleDetail(c *gin.Context) {
	var req bundle.ValueAddBundleDetailRequest

	if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
		service.Error1(c, err)
		return
	}

	res, err := service.BundleProvider.ValueAddBundleDetail(context.Background(), &req)
	if err != nil {
		service.Error1(c, err)
		return
	}

	service.Success1(c, res.Msg, res)
}
