package organizationroute

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

const (
	rootRoute    = ""
	detailRoute  = "/:org_uuid"
	parentRoute  = "/:org_uuid/parent"
	childRoute   = "/:org_uuid/child"
	addressRoute = "/:org_uuid/address"
	contactRoute = "/:org_uuid/contact"
	typeRoute    = "/type"
	nameRoute    = "/name"
)

func Register(r *echo.Group, cfg *config.Config, svc *applicationservice.Service) {
	ctrl := controllerInstance(cfg, svc)

	r.GET(rootRoute, ctrl.handle)
	r.POST(rootRoute, ctrl.handleAddOrganization)

	r.GET(detailRoute, ctrl.handleDetail)

	r.GET(typeRoute, ctrl.handleTypes)
	r.GET(nameRoute, ctrl.handleNameSearch)

	r.POST(parentRoute, ctrl.handleParent)
	r.POST(childRoute, ctrl.handleChild)

	r.POST(addressRoute, ctrl.handleAddAddress)
	r.PUT(addressRoute, ctrl.handleRemoveAddress)

	r.POST(contactRoute, ctrl.handleAddContact)
	r.PUT(contactRoute, ctrl.handleRemoveContact)
}
