package payments

import (
	"context"
	"errors"
	"testing"
	"time"

	"github.com/google/uuid"
)

// gateOnlyService builds a Service with a fixed clock and no store, usable only for the CreateOrder
// gate rejections that return before any store access.
func gateOnlyService() *Service {
	return &Service{clock: func() time.Time { return time.Unix(0, 0).UTC() }}
}

// TestCreateOrderGateRejections checks that CreateOrder fails closed — before touching the store —
// on an untrusted platform, the VK-iOS spend freeze, and a method whose funding segment the account
// does not hold.
func TestCreateOrderGateRejections(t *testing.T) {
	ctx := context.Background()
	acc, prod := uuid.New(), uuid.New()
	present := []Source{SourceDirect, SourceVK}

	cases := []struct {
		name string
		cxt  Context
	}{
		{"untrusted context", Context{}},
		{"vk-ios purchase freeze", Context{Kind: SourceVK, Subtype: SubtypeIOS}},
		{"method segment not attached", Context{Kind: SourceTelegram}},
	}
	for _, tc := range cases {
		t.Run(tc.name, func(t *testing.T) {
			_, err := gateOnlyService().CreateOrder(ctx, acc, tc.cxt, present, prod, "robokassa")
			if !errors.Is(err, ErrUntrusted) {
				t.Fatalf("CreateOrder(%s) = %v, want ErrUntrusted", tc.name, err)
			}
		})
	}
}
