package domaintest

import (
	"net/url"

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

type BasePlayerConfig struct {
	ID          int
	OD          domain.OpponentsDefeated
	NumVillages int
	AllPoints   int
	Rank        int
	TribeID     int
}

func NewBasePlayer(tb TestingTB, opts ...func(cfg *BasePlayerConfig)) domain.BasePlayer {
	tb.Helper()

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

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

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

	p, err := domain.NewBasePlayer(
		cfg.ID,
		gofakeit.LetterN(50),
		cfg.NumVillages,
		cfg.AllPoints,
		cfg.Rank,
		cfg.TribeID,
		cfg.OD,
		u,
	)
	require.NoError(tb, err)

	return p
}
