package bpjshandler

import (
	"net/http"

	/******************** main / transaction ********************/
	member "simrs-vx/internal/interface/main-handler/member"
	monitoring "simrs-vx/internal/interface/main-handler/monitoring"
	reference "simrs-vx/internal/interface/main-handler/reference"
	vclaimsep "simrs-vx/internal/interface/main-handler/vclaim-sep"
	vclaimsephist "simrs-vx/internal/interface/main-handler/vclaim-sep-hist"
	vclaimsepprint "simrs-vx/internal/interface/main-handler/vclaim-sep-print"

	/******************** actor ********************/

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

	/******************** infra ********************/
	ibpjs "simrs-vx/internal/infra/bpjs"
	gs "simrs-vx/internal/infra/gorm-setting"

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

	/******************** sources ********************/
	///// Internal
	validation "simrs-vx/internal/interface/main-handler/helper/validation"
	"simrs-vx/internal/interface/main-handler/home"
)

// One place route to relatively easier to manage, ESPECIALLY in tracking
func SetRoutes() http.Handler {
	/////
	a.RegisterExtCall(gs.Adjust)
	a.RegisterExtCall(zlc.Adjust)
	a.RegisterExtCall(lh.Populate)
	a.RegisterExtCall(ibpjs.SetConfig)
	a.RegisterExtCall(validation.RegisterValidation)

	r := http.NewServeMux()

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

	hk.GroupRoutes("/v1/vclaim-sep", r, hk.MapHandlerFunc{
		"POST /":       vclaimsep.O.Create,
		"PATCH /{id}":  vclaimsep.O.GetDetail,
		"DELETE /{id}": vclaimsep.O.Delete,
	})

	hk.GroupRoutes("/v1/vclaim-sep-hist", r, hk.MapHandlerFunc{
		"GET /": vclaimsephist.O.GetList,
	})

	hk.GroupRoutes("/v1/vclaim-sep-print", r, hk.MapHandlerFunc{
		"POST /": vclaimsepprint.O.Create,
	})

	hk.GroupRoutes("/v1/reference", r, hk.MapHandlerFunc{
		"GET /province":                                 reference.GetListProvince,
		"GET /regency/{provinceCode}":                   reference.GetListCities,
		"GET /district/{regencyCode}":                   reference.GetListDistrict,
		"GET /diagnose/{keyword}":                       reference.GetListDiagnose,
		"GET /diagnose-prb":                             reference.GetListDiagnosePrb,
		"GET /medicine-prb/{keyword}":                   reference.GetListMedicinePrb,
		"GET /unit/{unitCode}":                          reference.GetListUnit,
		"GET /healthcare/{healthcare}/{healthcareType}": reference.GetListHealthcare,
		"GET /responsible-doctor/{serviceType}/{serviceDate}/{specialistCode}": reference.GetListDoctor,
	})

	hk.GroupRoutes("/v1/member", r, hk.MapHandlerFunc{
		"GET /bpjs/{cardNumber}/{sepDate}": member.GetListByBpjsNumber,
		"GET /nik/{nik}/{sepDate}":         member.GetListByNik,
	})

	hk.GroupRoutes("/v1/monitoring", r, hk.MapHandlerFunc{
		"GET /visit/{date}/{serviceType}":              monitoring.GetListVisit,
		"GET /hist/{cardNumber}/{startDate}/{endDate}": monitoring.GetListHist,
	})

	/******************** actor ********************/

	/******************** sources ********************/

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