package domaintest

import (
	"time"

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

type TribeChangeConfig struct {
	ID         int
	ServerKey  string
	PlayerID   int
	OldTribeID int
	NewTribeID int
	CreatedAt  time.Time
}

func NewTribeChange(tb TestingTB, opts ...func(cfg *TribeChangeConfig)) domain.TribeChange {
	tb.Helper()

	cfg := &TribeChangeConfig{
		ID:         RandID(),
		ServerKey:  RandServerKey(),
		PlayerID:   RandID(),
		OldTribeID: RandID(),
		NewTribeID: RandID(),
		CreatedAt:  time.Now(),
	}

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

	tc, err := domain.UnmarshalTribeChangeFromDatabase(
		cfg.ID,
		cfg.ServerKey,
		cfg.PlayerID,
		cfg.OldTribeID,
		cfg.NewTribeID,
		cfg.CreatedAt,
	)
	require.NoError(tb, err)

	return tc
}
