package routers

import (
	"intent-system/pkg/api"
	"intent-system/pkg/middleware"

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

const (
	GroupRouterNewsV1 = "/api/v1/news"
	GroupRouterQaV1   = "/api/v1/qa"
	GroupRouterSubV1  = "/api/v1/sub"
	GroupRouterTagV1  = "/api/v1/tag"
)

const (
	RouterSubPathNewsList            = "/list"
	RouterSubPathNewsAdd             = "/add"
	RouterSubPathNewsEdit            = "/edit"
	RouterSubPathNewsDelete          = "/delete"
	RouterSubPathNewsCompare         = "/compare"
	RouterSubPathNewsPublish         = "/publish"
	RouterSubPathNewsDraftList       = "/draft/list"
	RouterSubPathNewsDraftEdit       = "/draft/edit"
	RouterSubPathNewsDraftPublish    = "/draft/publish"
	RouterSubPathNewsDraftDelete     = "/draft/delete"
	RouterSubPathNewsTag             = "/tag"
	RouterSubPathNewsAsync           = "/async"
	RouterSubPathNewsAsyncBatch      = "/asyncbatch"
	RouterSubPathNewsPullNew         = "/pullnew"
	RouterSubPathQaList              = "/list"
	RouterSubPathQaAdd               = "/add"
	RouterSubPathQaEdit              = "/edit"
	RouterSubPathQaDelete            = "/delete"
	RouterSubPathQaDraftList         = "/draft/list"
	RouterSubPathQaDraftEdit         = "/draft/edit"
	RouterSubPathQaDraftPublish      = "/draft/publish"
	RouterSubPathQaDraftDelete       = "/draft/delete"
	RouterSubPathSubscribeListToday  = "/list/today"
	RouterSubPathSubscribeListAll    = "/list/all"
	RouterSubPathSubscribeListPushed = "/list/pushed"
	RouterSubPathSubscribeEdit       = "/edit"
	RouterSubPathTagList             = "/list"
	RouterSubPathTagAdd              = "/add"
	RouterSubPathTagEdit             = "/edit"
	RouterSubPathTagDelete           = "/delete"
)

func InitRouterGroupBiz(r *gin.Engine, handlers api.BizApi) {
	groupNews := r.Group(GroupRouterNewsV1)

	groupNews.POST(RouterSubPathNewsList, handlers.NewsList)
	groupNews.POST(RouterSubPathNewsAsync, handlers.NewsAsync)
	groupNews.POST(RouterSubPathNewsAsyncBatch, handlers.NewsAsyncBatch)
	groupNews.POST(RouterSubPathNewsPullNew, handlers.NewsPullNew)
	groupNews.Use(middleware.JWT()) //use JWT token middleware
	{
		groupNews.POST(RouterSubPathNewsAdd, handlers.NewsAdd)
		groupNews.POST(RouterSubPathNewsEdit, handlers.NewsEdit)
		groupNews.POST(RouterSubPathNewsDelete, handlers.NewsDelete)
		groupNews.POST(RouterSubPathNewsCompare, handlers.NewsCompare)
		groupNews.POST(RouterSubPathNewsPublish, handlers.NewsPublish)
		groupNews.POST(RouterSubPathNewsDraftList, handlers.NewsDraftList)
		groupNews.POST(RouterSubPathNewsDraftEdit, handlers.NewsDraftEdit)
		groupNews.POST(RouterSubPathNewsDraftPublish, handlers.NewsDraftPublish)
		groupNews.POST(RouterSubPathNewsDraftDelete, handlers.NewsDraftDelete)
		groupNews.POST(RouterSubPathNewsTag, handlers.NewsTag)
	}

	groupQA := r.Group(GroupRouterQaV1)
	groupQA.POST(RouterSubPathQaList, handlers.QaList)
	groupQA.Use(middleware.JWT()) //use JWT token middleware
	{
		groupQA.POST(RouterSubPathQaAdd, handlers.QaAdd)
		groupQA.POST(RouterSubPathQaEdit, handlers.QaEdit)
		groupQA.POST(RouterSubPathQaDelete, handlers.QaDelete)
		groupQA.POST(RouterSubPathQaDraftList, handlers.QaDraftList)
		groupQA.POST(RouterSubPathQaDraftEdit, handlers.QaDraftEdit)
		groupQA.POST(RouterSubPathQaDraftPublish, handlers.QaDraftPublish)
		groupQA.POST(RouterSubPathQaDraftDelete, handlers.QaDraftDelete)
	}

	groupSub := r.Group(GroupRouterSubV1)
	groupSub.Use(middleware.JWT()) //use JWT token middleware
	{
		groupSub.POST(RouterSubPathSubscribeListToday, handlers.SubListToday)
		groupSub.POST(RouterSubPathSubscribeListAll, handlers.SubListAll)
		groupSub.POST(RouterSubPathSubscribeListPushed, handlers.SubListPushed)
		groupSub.POST(RouterSubPathSubscribeEdit, handlers.SubEditNews)
	}

	groupTag := r.Group(GroupRouterTagV1)
	groupTag.POST(RouterSubPathTagList, handlers.TagList)
	groupTag.Use(middleware.JWT()) //use JWT token middleware
	{
		groupTag.POST(RouterSubPathTagAdd, handlers.TagAdd)
		groupTag.POST(RouterSubPathTagEdit, handlers.TagEdit)
		groupTag.POST(RouterSubPathTagDelete, handlers.TagDelete)
	}
}
