package ports

import (
	"context"
	"reflect"
	"testing"
)

func TestAugmentPlannedHistorySequenceLocksBeforeFirstReservation(t *testing.T) {
	ctx := WithPlannedHistorySequenceLocks(context.Background(), nil)
	if ok := AugmentPlannedHistorySequenceLocks(ctx, []string{"field-z", "field-a", "field-z"}); !ok {
		t.Fatal("AugmentPlannedHistorySequenceLocks() = false, want true before consumption")
	}
	if got, want := PlannedHistorySequenceLocks(ctx), []string{"field-a", "field-z"}; !reflect.DeepEqual(got, want) {
		t.Fatalf("PlannedHistorySequenceLocks() = %#v, want %#v", got, want)
	}

	MarkPlannedHistorySequenceLocksConsumed(ctx)
	if ok := AugmentPlannedHistorySequenceLocks(ctx, []string{"field-b"}); ok {
		t.Fatal("AugmentPlannedHistorySequenceLocks() = true after consumption, want false")
	}
	if got := PlannedHistorySequenceLocks(ctx); got != nil {
		t.Fatalf("PlannedHistorySequenceLocks() after consumption = %#v, want nil", got)
	}
}

func TestAugmentPlannedHistorySequenceLocksRequiresAttemptState(t *testing.T) {
	if ok := AugmentPlannedHistorySequenceLocks(context.Background(), []string{"field-a"}); ok {
		t.Fatal("AugmentPlannedHistorySequenceLocks() = true without attempt state, want false")
	}
}
