package service

import (
	"testing"

	"github.com/pingcap/agent-git-service/internal/db"
)

func TestRepositorySyncVisibilityConfirmationIsDirectionBound(t *testing.T) {
	endpoints := []db.SyncBindingEndpoint{
		{Side: SyncSideA, Provider: SyncProviderAGS, RepositoryID: "42"},
		{Side: SyncSideB, Provider: SyncProviderGitHub, RepositoryID: "R_repo"},
	}
	forward, exposure := repositorySyncVisibilityConfirmation(endpoints, SyncSideA, "private", "public")
	if !exposure || forward == "" {
		t.Fatalf("private AGS to public GitHub should require confirmation: key=%q exposure=%t", forward, exposure)
	}
	if reverse, reverseExposure := repositorySyncVisibilityConfirmation(endpoints, SyncSideB, "private", "public"); reverseExposure || reverse != "" {
		t.Fatalf("public GitHub to private AGS should not require confirmation: key=%q exposure=%t", reverse, reverseExposure)
	}
	changed, exposure := repositorySyncVisibilityConfirmation(endpoints, SyncSideA, "internal", "public")
	if !exposure || changed == forward {
		t.Fatalf("visibility confirmation was not bound to current values: old=%q new=%q", forward, changed)
	}
}
