package routers

import (
	"bwallet/middleware/jwt"
	"bwallet/middleware/log"
	"bwallet/pkg/e"
	"github.com/gin-gonic/gin"

	"bwallet/pkg/upload"
	"bwallet/routers/api/app"
	"bwallet/routers/api/backend"
	"net/http"
)

func InitRouter() *gin.Engine {
	r := gin.New()

	r.Use(gin.Logger())

	r.Use(gin.Recovery())

	r.StaticFS("/upload/file", http.Dir(upload.GetFileFullPath()))
	//r.StaticFS("/qrcode", http.Dir(qrcode.GetQrCodeFullPath()))

	//r.POST("/auth", api.GetAuth)
	//r.POST("/upload", api.UploadFile)
	//r.POST("/upload", api.UploadImage)

	client := r.Group("/interface")

	//client.Use(aes.Aes())
	client.GET("/news", app.GetNews)
	client.GET("/one-news", app.GetOneNews)
	client.GET("/articles", app.GetArticle)
	client.GET("/article", app.GetOneArticle)
	client.GET("/transaction-fee", app.GetTransactionFee)
	client.GET("/app/expired", app.AppExpired)

	client.POST("/user", app.AddUser)
	client.POST("/live", app.AddLive)
	client.GET("/live", app.GetLiveInfos)
	client.PUT("/live-title", app.ModifyTitle)
	client.GET("/live-categories", app.GetLiveCategories)
	client.GET("/live-charge", app.GetLiveCharge)
	client.PUT("/live/status", app.LiveStatus)

	api := r.Group("/api")

	//api.Use(auth.AUTH())
	api.Use(jwt.JWT())
	api.POST("/log", backend.AddOperationLog)
	api.GET("/logs", backend.GetOperationLogs)
	api.Use(log.LogMiddleware(e.HandleTableName))
	{
		//api.POST("/upload",backend.Upload)
		api.GET("/coins", backend.GetCoins)
		api.POST("/coin", backend.AddCoin)
		api.GET("/coin", backend.GetCoin)
		api.PUT("/coin", backend.EditCoin)
		api.DELETE("/coin", backend.DeleteCoin)
		api.GET("/primary-chains", backend.GetCoinChains)
		api.GET("/types", backend.GetTypes)

		api.GET("/coin-relation", backend.GetWalletCoinRelationCoinRelations)
		api.POST("/coin-relation", backend.AddWalletCoinRelationCoinRelation)
		api.DELETE("/coin-relation", backend.DeleteWalletCoinRelationCoinRelation)
		//api.GET("/get-platform", backend.GetCoinsPlatform)

		api.GET("/wallets", backend.GetWallets)
		api.POST("/wallet", backend.AddWallet)
		api.GET("/wallet", backend.GetWallet)
		api.PUT("/wallet", backend.EditWallet)
		api.DELETE("/wallet", backend.DeleteWallet)

		api.GET("/news", backend.GetNews)
		api.POST("/news", backend.AddNews)
		api.GET("/one-news", backend.GetOneNews)
		api.PUT("/news", backend.EditNews)
		api.DELETE("/news", backend.DeleteNews)

		api.GET("/articles", backend.GetArticle)
		api.POST("/article", backend.AddArticle)
		api.GET("/article", backend.GetOneArticle)
		api.PUT("/article", backend.EditArticle)
		api.DELETE("/article", backend.DeleteArticle)

		api.GET("/chains", backend.GetChains)
		api.POST("/chain", backend.AddChain)
		api.GET("/chain", backend.GetChain)
		api.PUT("/chain", backend.EditChain)
		api.DELETE("/chain", backend.DeleteChain)
		api.GET("/user-chains", backend.GetUserChains)

		api.GET("/recommend-categories", backend.GetWalletRecommendCategories)
		api.POST("/recommend-category", backend.AddWalletRecommendCategory)
		api.GET("/recommend-category", backend.GetWalletRecommendCategory)
		api.DELETE("/recommend-category", backend.DeleteWalletRecommendCategory)
		api.PUT("/recommend-category", backend.EditWalletRecommendCategory)

		api.GET("/recommend-coins", backend.GetRecommendCoins)
		api.POST("/recommend-coin", backend.AddRecommendCoin)
		api.PUT("/recommend-coin", backend.EditRecommendCoin)
		api.DELETE("/recommend-coin", backend.DeleteRecommendCoin)
		api.GET("/transaction-fees", backend.GetTransactionFees)
		api.GET("/transaction-coins", backend.GetTransactionCoins)
		api.PUT("/transaction-fees", backend.EditTransactionFees)

		api.GET("/trusteeship-coins", backend.GetTrusteeshipCoins)
		api.POST("/trusteeship-coin", backend.AddTrusteeshipCoin)
		api.PUT("/trusteeship-coin", backend.EditTrusteeshipCoin)
		api.DELETE("/trusteeship-coin", backend.DeleteTrusteeshipCoin)

		api.GET("/supported-currencies", backend.GetSupportedCurrencies)
		api.POST("/supported-currency", backend.AddSupportedCurrency)
		api.GET("/supported-currency", backend.GetSupportedCurrency)
		api.PUT("/supported-currency", backend.EditSupportedCurrency)
		api.DELETE("/supported-currency", backend.DeleteSupportedCurrency)
		api.GET("/currencies", backend.GetCurrencies)

		api.GET("/supported-chains", backend.GetSupportedChains)
		api.POST("/supported-chain", backend.AddSupportedChain)
		api.DELETE("/supported-chain", backend.DeleteSupportedChain)

		api.GET("/live-categories", backend.GetLiveCategory)
		api.POST("/live-category", backend.AddLiveCategory)
		api.PUT("/live-category", backend.EditLiveCategory)
		api.DELETE("/live-category", backend.DeleteLiveCategory)

		api.GET("/live-info", backend.GetLiveInfo)
		api.PUT("/live-info", backend.VerifyLiveInfo)
		api.GET("/live-title-record", backend.GetLiveTitleRecord)
		api.PUT("/live-title-record", backend.VerifyLiveTitleRecord)

		api.GET("/live-banners", backend.GetLiveBanners)
		api.GET("/live-banner", backend.GetLiveBanner)
		api.POST("/live-banner", backend.AddLiveBanner)
		api.PUT("/live-banner", backend.EditLiveBanner)
		api.DELETE("/live-banner", backend.DeleteLiveBanner)

		api.GET("/live-charge", backend.GetLiveCharge)
		api.POST("/live-charge", backend.AddLiveCharge)
		api.PUT("/live-charge", backend.EditLiveCharge)

		api.GET("/managers", backend.GetManagers)
		//api.GET("/user", backend.GetUser)
		api.POST("/manager", backend.AddManager)
		api.PUT("/manager", backend.EditManager)
		api.DELETE("/manager", backend.DeleteManager)
	}

	return r
}
