package bundle

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

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

func CreateBundle(c *gin.Context) {
	var req bundle.BundleProfile

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

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

	service.Success(c, res)
}

func UpdateBundle(c *gin.Context) {
	var req bundle.BundleProfile

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

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

	service.Success(c, res)

}

func DeleteBundle(c *gin.Context) {
	var req bundle.DelBundleRequest

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

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

	service.Success(c, res)
}

func BundleList(c *gin.Context) {
	var req bundle.BundleListRequest

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

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

	service.Success(c, res)
}

func SaveBundleV2(c *gin.Context) {
	var req bundle.BundleProfile

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

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

	service.Success(c, res)
}

func BundleListV2(c *gin.Context) {
	var req bundle.BundleListRequest

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

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

	service.Success(c, res)
}
func BundleDetailV2(c *gin.Context) {
	var req bundle.BundleDetailRequest

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

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

	service.Success(c, res)
}
func HandShelf(c *gin.Context) {
	var req bundle.HandShelfRequest
	if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
		service.Error(c, err)
		return
	}
	res, err := service.BundleProvider.HandShelf(context.Background(), &req)
	if err != nil {
		service.Error(c, err)
		return
	}
	service.Success(c, res)
}
