package simgossynchandler

import (
	"net/http"

	/******************** infra ********************/
	gs "simrs-vx/internal/infra/gorm-setting"
	simgosdb "simrs-vx/internal/infra/simgos-db"

	/******************** pkg ********************/
	cmw "simrs-vx/pkg/cors-manager-mw"
	hc "simrs-vx/pkg/handler-crud-helper"
	lh "simrs-vx/pkg/lang-helper"
	handlerlogger "simrs-vx/pkg/middleware/handler-logger"
	zlc "simrs-vx/pkg/zerolog-ctx"

	/******************** external ********************/
	a "github.com/karincake/apem"
	hk "github.com/karincake/hongkue"

	/******************** internal ********************/
	"simrs-vx/internal/interface/main-handler/home"
	"simrs-vx/internal/interface/simgos-sync-handler/new/division"
	"simrs-vx/internal/interface/simgos-sync-handler/new/encounter"
	"simrs-vx/internal/interface/simgos-sync-handler/new/installation"
	"simrs-vx/internal/interface/simgos-sync-handler/new/patient"
	"simrs-vx/internal/interface/simgos-sync-handler/new/specialist"
	"simrs-vx/internal/interface/simgos-sync-handler/new/subspecialist"
	"simrs-vx/internal/interface/simgos-sync-handler/new/unit"
)

func SetRoutes() http.Handler {
	///
	a.RegisterExtCall(gs.Adjust)
	a.RegisterExtCall(zlc.Adjust)
	a.RegisterExtCall(lh.Populate)
	a.RegisterExtCall(simgosdb.SetInstance)

	r := http.NewServeMux()

	/******************** Main ********************/
	r.HandleFunc("/", home.Home)

	/******************** SvcToOld ******************/
	prefixnew := "/new-to-old"
	hc.SyncCrud(r, prefixnew+"/v1/installation", installation.O)
	hc.SyncCrud(r, prefixnew+"/v1/unit", unit.O)
	hc.SyncCrud(r, prefixnew+"/v1/division", division.O)
	hc.SyncCrud(r, prefixnew+"/v1/specialist", specialist.O)
	hc.SyncCrud(r, prefixnew+"/v1/subspecialist", subspecialist.O)
	hk.GroupRoutes(prefixnew+"/v1/patient", r, hk.MapHandlerFunc{
		"POST /":       patient.O.Create,
		"POST /log":    patient.O.CreateLog,
		"PATCH /{id}":  patient.O.Update,
		"DELETE /{id}": patient.O.Delete,
		"POST /nomr":   patient.O.GenerateNomr,
	})
	hk.GroupRoutes(prefixnew+"/v1/encounter", r, hk.MapHandlerFunc{
		"POST /":                          encounter.O.Create,
		"POST /log":                       encounter.O.CreateLog,
		"PATCH /{id}":                     encounter.O.Update,
		"DELETE /{id}":                    encounter.O.Delete,
		"PATCH /{id}/checkin":             encounter.O.Checkin,
		"PATCH /{id}/checkout":            encounter.O.Checkout,
		"PATCH /{id}/update-status":       encounter.O.UpdateStatus,
		"PATCH /{id}/req-switch-unit":     encounter.O.RequestSwitchUnit,
		"PATCH /{id}/approve-switch-unit": encounter.O.ApproveSwitchUnit,
		"PATCH /{id}/cancel-switch-unit":  encounter.O.CancelSwitchUnit,
	})

	/******************** SvcToNew ******************/
	//prefixold := "/old-to-new"

	return cmw.SetCors(handlerlogger.SetLog(r))
}
