// Package daemon — dispatch_handler.go mounts the orca.v1.Dispatch
// service on the daemon's HTTP server. The service is registered as
// two handlers (POST /orca.v1.Dispatch/Submit and /Status) and is
// gated on the mTLS state — if the server is in plaintext mode
// (v0.1 compat), the handlers refuse to serve.
package daemon

import (
	"net/http"

	"git.cloudinit.dev/coreci/orca/internal/transport"
)

// DispatchHandlers groups the Submit and Status handlers so they
// can be registered as a unit on the daemon mux.
type DispatchHandlers struct {
	Submit *transport.SubmitHandler
	Status *transport.StatusHandler
}

// NewDispatchHandlers builds the dispatch handler pair from a
// transport.Dispatcher (the engine layer satisfies this).
func NewDispatchHandlers(d transport.Dispatcher, dedupe *transport.IdempotencyStore) *DispatchHandlers {
	if dedupe == nil {
		dedupe = transport.NewIdempotencyStore()
	}
	return &DispatchHandlers{
		Submit: transport.NewSubmitHandler(d, dedupe),
		Status: transport.NewStatusHandler(d),
	}
}

// Mount registers Submit and Status on the given mux. Called by the
// daemon's mux builder.
func (h *DispatchHandlers) Mount(mux *http.ServeMux) {
	mux.Handle("/orca.v1.Dispatch/Submit", h.Submit)
	mux.Handle("/orca.v1.Dispatch/Status", h.Status)
}
