package domaintest

import (
	"gitea.dwysokinski.me/twhelp/corev3/internal/domain"
	"github.com/brianvoe/gofakeit/v7"
	"github.com/stretchr/testify/require"
)

type VersionCursorConfig struct {
	Code string
}

func NewVersionCursor(tb TestingTB, opts ...func(cfg *VersionCursorConfig)) domain.VersionCursor {
	tb.Helper()

	cfg := &VersionCursorConfig{
		Code: RandVersionCode(),
	}

	for _, opt := range opts {
		opt(cfg)
	}

	vc, err := domain.NewVersionCursor(cfg.Code)
	require.NoError(tb, err)

	return vc
}

type VersionConfig struct {
	Code string
}

func NewVersion(tb TestingTB, opts ...func(cfg *VersionConfig)) domain.Version {
	tb.Helper()

	cfg := &VersionConfig{
		Code: RandVersionCode(),
	}

	for _, opt := range opts {
		opt(cfg)
	}

	v, err := domain.UnmarshalVersionFromDatabase(
		cfg.Code,
		gofakeit.LetterN(10),
		gofakeit.DomainName(),
		gofakeit.TimeZoneRegion(),
	)
	require.NoError(tb, err)

	return v
}

func RandVersionCode() string {
	return gofakeit.LetterN(2)
}
