package app

import (
	"context"

	"github.com/tidbcloud/AgentTeam/internal/store/access"
	"github.com/tidbcloud/AgentTeam/internal/store/message"
	"github.com/tidbcloud/AgentTeam/internal/store/rewind"
)

func (store *Store) Rewind() *rewind.Store {
	return rewind.New(store.db, rewind.Options{
		LookupMessageChannelID: store.LookupMessageChannelID,
		ResolveAuthorizedHumanMessageTarget: func(ctx context.Context, userID string, workspaceID string, channelID string) (access.HumanWorkspaceMember, message.ThreadAccess, error) {
			return store.resolveAuthorizedHumanMessageTarget(ctx, userID, workspaceID, channelID, channelReadAction, dmReadAction, threadReadAction)
		},
		RequireAgentOperation:          store.requireAgentOperation,
		ReplaceReplyThreadParticipants: message.ReplaceReplyThreadParticipants,
		MergeReplyThreadParticipantIDs: message.MergeReplyThreadParticipantIDs,
	})
}
