package domaintest

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

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)
	}

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

	return s
}

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