package main

import (
	"fmt"
	"net/http"
	"server/msg"

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

var list []*msg.ShopItem = make([]*msg.ShopItem, 0)

func MakeShop() []*msg.ShopItem {
	if len(list) == 10 {
		return list
	}
	for i := range 10 {
		list = append(list, &msg.ShopItem{
			Id:    fmt.Sprintf("%d", i+1),
			Name:  fmt.Sprintf("Item:%d", i+1),
			Price: int32((i + 1) * 100),
			Num:   int32((i + 1) * 50),
		})
	}
	return list
}

func ReqShop(c *gin.Context) {
	req := c.MustGet("protobuf_data").(*msg.ReqShop)
	if req.ShopType == 1 {
		c.ProtoBuf(http.StatusOK, &msg.ResShop{
			Success: true,
			List:    MakeShop(),
		})
	}
}
