package domaintest

import (
	"time"

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

type VillageConfig struct {
	ID        int
	ServerKey string
	PlayerID  int
}

func NewVillage(tb TestingTB, opts ...func(cfg *VillageConfig)) domain.Village {
	tb.Helper()

	cfg := &VillageConfig{
		ID:        RandID(),
		ServerKey: RandServerKey(),
		PlayerID:  gofakeit.IntRange(0, 10000),
	}

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

	v, err := domain.UnmarshalVillageFromDatabase(
		cfg.ID,
		cfg.ServerKey,
		gofakeit.LetterN(50),
		gofakeit.IntRange(1, 10000),
		gofakeit.IntRange(1, 1000),
		gofakeit.IntRange(1, 1000),
		gofakeit.LetterN(3),
		0,
		cfg.PlayerID,
		gofakeit.URL(),
		time.Now(),
	)
	require.NoError(tb, err)

	return v
}
