package testkit

import (
	"testing"

	"github.com/stretchr/testify/require"

	"github.com/tidbcloud/AgentTeam/internal/coredb"
)

type accessorTestDB struct{ coredb.DB }

func TestNewWrapAndDomainAccessors(t *testing.T) {
	t.Parallel()

	require.Nil(t, Wrap(nil))
	var nilStore *Store
	require.Nil(t, nilStore.Admin())
	require.Nil(t, nilStore.Workspace())

	db := &accessorTestDB{}
	root := New(db, nil, 7)
	require.NotNil(t, root)
	require.NotNil(t, root.Graph)
	require.Same(t, db, root.DB)

	wrapped := Wrap(root.Graph)
	require.Same(t, root.Graph, wrapped.Graph)
	require.Same(t, root.Graph.Admin, wrapped.Admin())
	require.Same(t, root.Graph.Agent, wrapped.Agent())
	require.Same(t, root.Graph.AgentOps, wrapped.AgentOps())
	require.Same(t, root.Graph.PrivateAgents, wrapped.PrivateAgents())
	require.Same(t, root.Graph.App, wrapped.App())
	require.Same(t, root.Graph.Attachment, wrapped.Attachment())
	require.Same(t, root.Graph.Channel, wrapped.Channel())
	require.Same(t, root.Graph.Identity, wrapped.Identity())
	require.Same(t, root.Graph.Message, wrapped.Message())
	require.Same(t, root.Graph.Reaction, wrapped.Reaction())
	require.Same(t, root.Graph.Rewind, wrapped.Rewind())
	require.Same(t, root.Graph.Review, wrapped.Review())
	require.Same(t, root.Graph.Workspace, wrapped.Workspace())
}
