package v1

import (
	"bwallet/pkg/errno"
	"bwallet/pkg/handler"
	"bwallet/pkg/util"
	"bwallet/service/auth_service"
	"bwallet/service/wallet_coin_relation_service"
	"github.com/gin-gonic/gin"
)

func GetWalletCoinRelationCoinRelations(c *gin.Context) {

	token := c.Request.Header.Get("Token")
	authService := auth_service.Auth{Token: token}
	auth, _ := authService.GetUserInfo()
	var platform_id int
	platform_id = auth.PlatformId

	walletCoinRelateionService := wallet_coin_relation_service.WalletCoinRelation{}

	walletCoinRelateionService = wallet_coin_relation_service.WalletCoinRelation{
		PlatformId: platform_id,
		PageNum:    util.GetPage(c),
		PageSize:   util.GetLimit(c),
	}

	total, err := walletCoinRelateionService.Count()
	if err != nil {
		//handler.SendResponse(c, errno.ErrCountWalletCoinRelation, nil)
		return
	}

	coins, err := walletCoinRelateionService.GetAll()
	if err != nil {
		handler.SendResponse(c, errno.InternalServerError, nil)
		return
	}

	data := make(map[string]interface{})
	data["items"] = coins
	data["total"] = total

	handler.SendResponse(c, nil, data)
}
