package router

import (
	"bitbucket.org/nemt/nemt-portal-api/application/applicationservice"
	"bitbucket.org/nemt/nemt-portal-api/application/notificationservice"
	"bitbucket.org/nemt/nemt-portal-api/application/tncservice"
	"bitbucket.org/nemt/nemt-portal-api/infra/config"
	"bitbucket.org/nemt/nemt-portal-api/server/router/authenticateroute"
	"bitbucket.org/nemt/nemt-portal-api/server/router/docsroute"
	"bitbucket.org/nemt/nemt-portal-api/server/router/eligibilityroute"
	"bitbucket.org/nemt/nemt-portal-api/server/router/externalroute"
	"bitbucket.org/nemt/nemt-portal-api/server/router/healthroute"
	"bitbucket.org/nemt/nemt-portal-api/server/router/lyfthookroute"
	"bitbucket.org/nemt/nemt-portal-api/server/router/notificationroute"
	"bitbucket.org/nemt/nemt-portal-api/server/router/organizationroute"
	"bitbucket.org/nemt/nemt-portal-api/server/router/passwordresetroute"
	"bitbucket.org/nemt/nemt-portal-api/server/router/placesroute"
	"bitbucket.org/nemt/nemt-portal-api/server/router/profileroute"
	"bitbucket.org/nemt/nemt-portal-api/server/router/providerroute"
	"bitbucket.org/nemt/nemt-portal-api/server/router/selfregisterroute"
	"bitbucket.org/nemt/nemt-portal-api/server/router/tncroute"
	"bitbucket.org/nemt/nemt-portal-api/server/router/twilioroute"
	"bitbucket.org/nemt/nemt-portal-api/server/router/usersroute"
	"bitbucket.org/nemt/nemt-portal-api/server/router/visitroute"
	"github.com/labstack/echo"
)

// Register registers the API routes
func Register(e *echo.Echo, cfg *config.Config, svc *applicationservice.Service, tnc *tncservice.Service, notification *notificationservice.Service) {
	healthroute.Register(e.Group("/health"))
	prefixGroup := e.Group(cfg.HTTP.Prefix)

	if cfg.App.Debug {
		docsroute.Register(prefixGroup.Group("/docs"), cfg)
	}

	notificationroute.Register(prefixGroup.Group("/notification"), cfg, svc, tnc, notification)
	twilioroute.Register(prefixGroup.Group("/twilio"), cfg, svc, tnc, notification)
	lyfthookroute.Register(prefixGroup.Group("/lyfthook"), cfg, svc, tnc, notification)
	externalroute.Register(prefixGroup.Group("/ext"), cfg, svc, tnc, notification)
	authenticateroute.Register(prefixGroup.Group("/authenticate"), cfg, svc)
	selfregisterroute.Register(prefixGroup.Group("/selfregister"), cfg, svc)
	passwordresetroute.Register(prefixGroup.Group("/passwordreset"), cfg, svc)

	appGroup := prefixGroup.Group("/" + cfg.App.Name)
	usersroute.Register(appGroup.Group("/users"), cfg, svc)
	eligibilityroute.Register(appGroup.Group("/eligibility"), cfg, svc)
	tncroute.Register(appGroup.Group("/rides"), cfg, svc, tnc, notification)
	visitroute.Register(appGroup.Group("/visits"), cfg, svc, tnc)
	providerroute.Register(appGroup.Group("/provider"), cfg, svc)
	placesroute.Register(appGroup.Group("/places"), cfg, svc)
	profileroute.Register(appGroup.Group("/profile"), cfg, svc)
	organizationroute.Register(appGroup.Group("/organization"), cfg, svc)

}
