package domaintest

import (
	"net/url"

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

type BaseTribeConfig struct {
	ID          int
	Tag         string
	OD          domain.OpponentsDefeated
	NumVillages int
	AllPoints   int
	Rank        int
}

func NewBaseTribe(tb TestingTB, opts ...func(cfg *BaseTribeConfig)) domain.BaseTribe {
	tb.Helper()

	cfg := &BaseTribeConfig{
		ID:          RandID(),
		Tag:         RandTribeTag(),
		OD:          NewOpponentsDefeated(tb),
		NumVillages: gofakeit.IntRange(1, 10000),
		AllPoints:   gofakeit.IntRange(1, 10000),
		Rank:        gofakeit.IntRange(1, 10000),
	}

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

	u, err := url.ParseRequestURI(gofakeit.URL())
	require.NoError(tb, err)

	t, err := domain.NewBaseTribe(
		cfg.ID,
		gofakeit.LetterN(50),
		cfg.Tag,
		gofakeit.IntRange(1, 10000),
		cfg.NumVillages,
		gofakeit.IntRange(1, 10000),
		cfg.AllPoints,
		cfg.Rank,
		cfg.OD,
		u,
	)
	require.NoError(tb, err)

	return t
}
