package buntest

import (
	"context"
	"io/fs"

	"gitea.dwysokinski.me/twhelp/corev3/internal/bun/bunmodel"
	"github.com/stretchr/testify/require"
	"github.com/uptrace/bun"
	"github.com/uptrace/bun/dbfixture"
)

type Fixture struct {
	f *dbfixture.Fixture
}

func NewFixture(bunDB *bun.DB) *Fixture {
	bunDB.RegisterModel(
		(*bunmodel.Version)(nil),
		(*bunmodel.Server)(nil),
		(*bunmodel.Tribe)(nil),
		(*bunmodel.Player)(nil),
		(*bunmodel.Village)(nil),
		(*bunmodel.Ennoblement)(nil),
		(*bunmodel.TribeChange)(nil),
	)
	return &Fixture{
		f: dbfixture.New(bunDB),
	}
}

//nolint:revive
func (f *Fixture) Load(tb TestingTB, ctx context.Context, fsys fs.FS, names ...string) {
	tb.Helper()
	require.NoError(tb, f.f.Load(ctx, fsys, names...))
}
