package mutil

import (
	"net/http"

	mutilimp "github.com/tech/sendico/server/internal/mutil/param/internal"
	"go.mongodb.org/mongo-driver/v2/bson"
)

type ParamHelper interface {
	Name() string
	RefName() string
	GetID(r *http.Request) string
	GetRef(r *http.Request) (bson.ObjectID, error)
	AddRef(base string) string
}

func CreatePH(resource string) ParamHelper {
	return mutilimp.CreateImp(resource)
}

type DependentParamHelper struct {
	p ParamHelper
	c ParamHelper
}

func (ph *DependentParamHelper) Parent() ParamHelper {
	return ph.p
}

func (ph *DependentParamHelper) Child() ParamHelper {
	return ph.c
}

func (ph *DependentParamHelper) AddRef(base string) string {
	return ph.Parent().AddRef(ph.Child().AddRef(base))
}

func CreateDPH(pRes, cRes string) *DependentParamHelper {
	return &DependentParamHelper{
		p: CreatePH(pRes),
		c: CreatePH(cRes),
	}
}
