package serverconfig

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

// SetMiddlewares attaches middlewares to server
func SetMiddlewares(server *echo.Echo, cfg *config.Config, log *logger.Logger, svc *service.Service, appsvc *applicationservice.Service) error {
	setRecoverMiddleware(server)
	setGZIPMiddleware(server)
	setRequestIDMiddleware(server)
	setLogMiddleware(server, log)
	setCORSMiddleware(server, cfg)
	setBodyLimitMiddleware(server)
	setRateLimitMiddleware(server)
	//setAuthorizationMiddleware(server, log, cfg, appsvc)

	err := setJWTMiddleware(server, cfg)
	if err != nil {
		return errors.Wrap(err)
	}

	return nil
}
