package usersroute

import (
	"bitbucket.org/nemt/nemt-portal-api/application/applicationservice"
	"bitbucket.org/nemt/nemt-portal-api/infra/config"
	"github.com/labstack/echo"
)

const (
	rootRoute                = "/"
	idRoute                  = "/:user_uuid/"
	memberRoute              = "/member"
	memberDetailRoute        = "/member/:user_uuid"
	memberAddressRoute       = "/member/:user_uuid/address"
	memberRemoveAddressRoute = "/member/:user_uuid/address/:address_uuid"
	userRoute                = "/portal"
	userDetailRoute          = "/portal/:user_uuid"
	userAddressRoute         = "/portal/:user_uuid/address"
	userRemoveAddressRoute   = "/portal/:user_uuid/address/:address_uuid"
	userContactRoute         = "/portal/:user_uuid/contact"
	userRemoveContactRoute   = "/portal/:user_uuid/contact/:contact_uuid"
	portalRoute              = "/portal"
	portalBulkRoute          = "/portal/bulk"
	contacttypeRoute         = "/contacttype"

	tokenInfoRoute = "/tokeninfo"
)

// Register registers the routes in the echo group
func Register(r *echo.Group, cfg *config.Config, svc *applicationservice.Service) {
	ctrl := controllerInstance(svc, cfg)

	r.GET(rootRoute, ctrl.handleGetAll)
	r.GET(idRoute, ctrl.handleGetByID)

	r.POST(memberAddressRoute, ctrl.handleMemberAddress)
	r.PUT(memberRemoveAddressRoute, ctrl.handleRemoveAddress)
	r.GET(memberDetailRoute, ctrl.handleMemberDetail)
	r.GET(memberRoute, ctrl.handleGetMember)

	r.GET(userDetailRoute, ctrl.handlePortalDetail)
	r.GET(userRoute, ctrl.handleGetPortal)
	r.POST(userAddressRoute, ctrl.handlePortalAddress)
	r.PUT(userRemoveAddressRoute, ctrl.handleRemoveAddress)

	r.POST(userContactRoute, ctrl.handlePortalContact)
	r.PUT(userRemoveContactRoute, ctrl.handleRemoveContact)

	//Can be cached
	r.GET(contacttypeRoute, ctrl.handleContactType)

	r.POST(memberRoute, ctrl.handleMember)
	r.POST(portalRoute, ctrl.handlePortal)
	r.POST(portalBulkRoute, ctrl.handleBulkPortal)

	if cfg.App.Debug {
		r.GET(tokenInfoRoute, ctrl.handleTokenInfo)
	}
}
