package services

import (
	"database/sql"

	"github.com/nexuscrm/analytics"
	"github.com/nexuscrm/audit"
)

// auditHistoryQueryFactory is the composition-root adapter that inverts the
// analytics -> features/audit edge. Analytics declares the HistoryQueryFactory
// consumer interface; this adapter closes over audit.NewHistoryQueryService so
// the analytics module never imports the audit (backend/internal) package.
//
// The analytics-side MetadataSource / PermissionChecker / HistoryViewResolver
// interfaces structurally satisfy audit's HistoryMetadataProvider /
// HistoryPermissionProvider / HistoryViewResolver, so they pass straight
// through.
type auditHistoryQueryFactory struct{}

func (auditHistoryQueryFactory) Build(
	db *sql.DB,
	metadata analytics.MetadataSource,
	permissions analytics.PermissionChecker,
	views analytics.HistoryViewResolver,
) analytics.HistoryQuery {
	return audit.NewHistoryQueryService(db, metadata, permissions, views)
}
