package router

import (
	"github.com/gin-gonic/gin"
	_ "github.com/gin-gonic/gin"
	"go-admin/pkg/jwtauth"
	jwt "go-admin/pkg/jwtauth"
)

var (
	routerNoCheckRole = make([]func(*gin.RouterGroup), 0)
	routerCheckRole   = make([]func(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware), 0)
)

// InitExamplesRouter 路由示例
func InitExamplesRouter(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware) *gin.Engine {

	// 无需认证的路由
	examplesNoCheckRoleRouter(r)
	// 需要认证的路由
	examplesCheckRoleRouter(r, authMiddleware)

	return r
}

// 无需认证的路由示例
func examplesNoCheckRoleRouter(r *gin.Engine) {
	// 可根据业务需求来设置接口版本
	v1 := r.Group("/api/v1")
	// 空接口防止v1定义无使用报错
	v1.GET("/nilcheckrole", nil)

	for _, f := range routerNoCheckRole {
		f(v1)
	}

	// {{无需认证路由自动补充在此处请勿删除}}
	registerSysFileInfoRouter(v1)
	registerSysFileDirRouter(v1)

	// 商品
	registerGoodsManageUnAuthRouter(v1)
	// 用户
	registerUserManageUnAuthRouter(v1)
	// 门店
	registerStoreManageUnAuthRouter(v1)
	// 订单
	registerOrderManageUnAuthRouter(v1)
	// 库存
	registerStockManageUnAuthRouter(v1)
	// 活动
	registerActivityManageUnAuthRouter(v1)
	// 商城
	registerMallManageUnAuthRouter(v1)
	// 共享卡
	registerShareManageUnAuthRouter(v1)
	// 合作商
	registerCooperativeManageUnAuthRouter(v1)
	// 回收卡
	registerRecycleCardManageUnAuthRouter(v1)

	// 营销管理
	registerMarketingManageUnAuthRouter(v1)
}

// 需要认证的路由示例
func examplesCheckRoleRouter(r *gin.Engine, authMiddleware *jwtauth.GinJWTMiddleware) {
	// 可根据业务需求来设置接口版本
	v1 := r.Group("/api/v1")
	// 空接口防止v1定义无使用报错
	v1.GET("/checkrole", nil)

	for _, f := range routerCheckRole {
		f(v1, authMiddleware)
	}

	// {{认证路由自动补充在此处请勿删除}}
	registerSysContentRouter(v1, authMiddleware)
	registerSysCategoryRouter(v1, authMiddleware)

	// 商品
	registerGoodsManageRouter(v1, authMiddleware)
	// 活动
	registerActivityManageRouter(v1, authMiddleware)
	// 共享卡
	registerShareManageAuthRouter(v1, authMiddleware)
	// 门店
	registerStoreManageRouter(v1, authMiddleware)
	// 合作商
	registerCooperativeManageRouter(v1, authMiddleware)
	// 用户
	registerUserManageRouter(v1, authMiddleware)
	// 订单
	registerOrderManageRouter(v1, authMiddleware)
	// 商城
	registerMallManageRouter(v1, authMiddleware)
	// 回收卡
	registerRecycleCardManageRouter(v1, authMiddleware)
	// 游戏卡库存
	registerStockManageRouter(v1, authMiddleware)

	// 供应商
	registerSupplierRouter(v1, authMiddleware)
	// 商品分类
	registerCategoryRouter(v1, authMiddleware)
	// 商品资料
	registerCommodityRouter(v1, authMiddleware)
	// 收付款账号设置
	registerCashierRouter(v1, authMiddleware)
	// erp库存管理
	registerInventoryManageRouter(v1, authMiddleware)
	// 零售订单管理
	registerErpOrderManageRouter(v1, authMiddleware)
	// 采购管理
	registerErpPurchaseManageRouter(v1, authMiddleware)
	// 决策中心
	registerErpDecisionRouter(v1, authMiddleware)
	// 营销管理
	registerMarketingManageRouter(v1, authMiddleware)
	// 维修管理
	registerRepairRouter(v1, authMiddleware)
	// 消息中心
	registerMessageCenterRouter(v1, authMiddleware)
	// 积分抽奖
	registerLotteryRouter(v1, authMiddleware)
}
