package privateagent

import (
	"context"
	"time"

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

func (store *Store) EnsureScopeProjectionForTarget(ctx context.Context, tx coredb.Tx, target message.ThreadAccess) (string, error) {
	return store.ensureScopeProjectionForTarget(ctx, tx, target)
}

func (store *Store) EnsureChannelScopeProjection(ctx context.Context, execer coredb.QueryExecer, channelID string) (string, error) {
	return store.ensureChannelScopeProjection(ctx, execer, channelID)
}

func (store *Store) EnsureDMScopeProjection(ctx context.Context, execer coredb.QueryExecer, dmThreadID string) (string, error) {
	return store.ensureDMScopeProjection(ctx, execer, dmThreadID)
}

func (store *Store) EnsureReplyThreadScopeProjection(ctx context.Context, execer coredb.QueryExecer, threadChannelID string) (string, error) {
	return store.ensureReplyThreadScopeProjection(ctx, execer, threadChannelID)
}

func (store *Store) EnsureScopeParticipantProjection(ctx context.Context, execer coredb.QueryExecer, scopeID string, memberID string, agentState string, createdAt time.Time) error {
	return store.ensureScopeParticipantProjection(ctx, execer, scopeID, memberID, agentState, createdAt)
}

func (store *Store) EnsureChannelScopeParticipantProjection(ctx context.Context, execer coredb.QueryExecer, channelID string, memberID string, agentState string, createdAt time.Time) error {
	return store.ensureChannelScopeParticipantProjection(ctx, execer, channelID, memberID, agentState, createdAt)
}

func (store *Store) SetScopeParticipantArchivedState(ctx context.Context, execer coredb.QueryExecer, scopeID string, memberID string, archivedAt *time.Time) error {
	return store.setScopeParticipantArchivedState(ctx, execer, scopeID, memberID, archivedAt)
}

func (store *Store) EnsurePublicChannelAgentEntryProjection(ctx context.Context, execer coredb.QueryExecer, workspaceID string, channelID string, agentMemberID string, createdAt time.Time) error {
	return store.ensurePublicChannelAgentEntryProjection(ctx, execer, workspaceID, channelID, agentMemberID, createdAt)
}

func (store *Store) EnsureAllChannelScopeParticipantProjection(ctx context.Context, tx coredb.Tx, workspaceID string, memberID string, agentState string, createdAt time.Time) error {
	return store.ensureAllChannelScopeParticipantProjection(ctx, tx, workspaceID, memberID, agentState, createdAt)
}

func (store *Store) MarkMemberScopeProjectionsRemoved(ctx context.Context, execer coredb.QueryExecer, memberID string, removedAt time.Time) error {
	return store.markMemberScopeProjectionsRemoved(ctx, execer, memberID, removedAt)
}

func (store *Store) ArchiveScopeProjection(ctx context.Context, execer coredb.QueryExecer, scopeID string, archivedAt time.Time) error {
	return store.archiveScopeProjection(ctx, execer, scopeID, archivedAt)
}

func (store *Store) MarkScopeParticipantProjectionRemoved(ctx context.Context, execer coredb.QueryExecer, scopeID string, memberID string, removedAt time.Time) error {
	return store.markScopeParticipantProjectionRemoved(ctx, execer, scopeID, memberID, removedAt)
}

func (store *Store) MarkPublicChannelAgentEntryProjectionRemoved(ctx context.Context, execer coredb.QueryExecer, channelID string, agentMemberID string, removedAt time.Time) error {
	return store.markPublicChannelAgentEntryProjectionRemoved(ctx, execer, channelID, agentMemberID, removedAt)
}

func (store *Store) LookupAllChannelID(ctx context.Context, queryer interface {
	QueryRow(context.Context, string, ...any) coredb.Row
}, workspaceID string) (string, error) {
	return store.lookupAllChannelID(ctx, queryer, workspaceID)
}

func (store *Store) LoadAgentEntryOwner(ctx context.Context, queryer interface {
	QueryRow(context.Context, string, ...any) coredb.Row
}, workspaceID string, agentID string) (AgentEntryOwner, error) {
	return store.loadAgentEntryOwner(ctx, queryer, workspaceID, agentID)
}

func (store *Store) LoadActiveChannelAgentEntry(ctx context.Context, queryer interface {
	QueryRow(context.Context, string, ...any) coredb.Row
}, channelID string, agentMemberID string) (ActiveChannelAgentEntry, bool, error) {
	return store.loadActiveChannelAgentEntry(ctx, queryer, channelID, agentMemberID)
}

func (store *Store) EnsurePublicChannelAgentEntryAllowed(ctx context.Context, queryer interface {
	QueryRow(context.Context, string, ...any) coredb.Row
}, channelID string, agentMemberID string) error {
	return store.ensurePublicChannelAgentEntryAllowed(ctx, queryer, channelID, agentMemberID)
}

func (store *Store) EnsurePrivateChannelAgentEntry(ctx context.Context, tx coredb.Tx, workspaceID string, channelID string, agent AgentEntryOwner, createdAt time.Time) error {
	return store.ensurePrivateChannelAgentEntry(ctx, tx, workspaceID, channelID, agent, createdAt)
}

func (store *Store) RemovePrivateEntriesForOwnerHostChannel(ctx context.Context, execer coredb.QueryExecer, ownerMemberID string, hostChannelID string, removedAt time.Time) error {
	return store.removePrivateEntriesForOwnerHostChannel(ctx, execer, ownerMemberID, hostChannelID, removedAt)
}

func (store *Store) RemovePrivateEntriesForOwner(ctx context.Context, execer coredb.QueryExecer, ownerMemberID string, removedAt time.Time) error {
	return store.removePrivateEntriesForOwner(ctx, execer, ownerMemberID, removedAt)
}
