/*
 * Copyright 2026 Oleg Borodin <onborodin@gmail.com>
 *
 * This work is published and licensed under a Creative Commons
 * Attribution-NonCommercial-NoDerivatives 4.0 International License.
 *
 * Distribution of this work is permitted, but commercial use and
 * modifications are strictly prohibited.
 */
package handler

import (
	"mstore/app/logger"
	"mstore/app/maindb"
	"mstore/app/operator"
	"mstore/app/router"

	yaml "go.yaml.in/yaml/v4"
)

type HandlerParams struct {
	Operator *operator.Operator
	MainDB   *maindb.Database
}

type Handler struct {
	oper *operator.Operator
	mdb  *maindb.Database
	logg *logger.Logger
}

func NewHandler(params *HandlerParams) (*Handler, error) {
	var err error
	hand := &Handler{
		oper: params.Operator,
		mdb:  params.MainDB,
	}
	hand.logg = logger.NewLoggerWithSubject("handler")
	return hand, err
}

func (hand *Handler) DumpHeaders(label string, rctx *router.Context) {
	headers := rctx.GetHeaders()
	yamlData, _ := yaml.Marshal(headers)
	hand.logg.Debugf("%s:\n%s\n", label, string(yamlData))
}
