/**
 * Dual Database Stub
 *
 * This module previously handled dual-write to both Prisma/Convex and Supabase.
 * Since the project has migrated fully to Convex, these functions are now no-ops
 * that simply delegate to the primary database call (or do nothing for the
 * Supabase sync portion).
 *
 * The importing route files are left untouched -- these stubs satisfy their
 * imports without introducing any Supabase dependency.
 */

import { logger } from "@/lib/logger";

/**
 * Save a user record to the primary database.
 * Previously also synced to Supabase -- now a no-op for the secondary write.
 */
export async function saveUserToBoth(userData: {
  id: string;
  email: string;
  name?: string | null;
  password?: string;
  emailVerified?: Date | null;
  role?: string;
  isActive?: boolean;
}): Promise<void> {
  // Primary write is handled by the caller via organizationService / prisma adapter.
  // Supabase sync removed during Convex migration.
  logger.debug("[dual-database] saveUserToBoth called (Supabase sync disabled)", {
    userId: userData.id,
  });
}

/**
 * Execute a primary database operation and optionally sync to a secondary store.
 * The secondary sync is now a no-op.
 *
 * @param primaryOperation - async function that performs the primary DB write
 * @param _tableName - target table name (unused, kept for API compat)
 * @param _mapper - maps the primary result for secondary insert (unused)
 * @returns The result of the primary operation
 */
export async function saveToBothDatabases<T>(
  primaryOperation: () => Promise<T>,
  _tableName?: string,
  _mapper?: (result: T) => Record<string, unknown>,
): Promise<T> {
  // Execute primary operation only -- Supabase dual-write removed.
  const result = await primaryOperation();
  logger.debug("[dual-database] saveToBothDatabases completed (Supabase sync disabled)", {
    table: _tableName,
  });
  return result;
}

/**
 * Save an audit log entry to the primary database.
 * Previously also synced to Supabase -- now a no-op for the secondary write.
 */
export async function saveAuditLogToBoth(auditData: {
  id: string;
  userId: string;
  type: string;
  action: string;
  success: boolean;
  ip?: string;
  userAgent?: string;
  metadata?: Record<string, unknown>;
}): Promise<void> {
  // Audit logs are now handled through the Convex adapter.
  // Supabase sync removed during Convex migration.
  logger.debug("[dual-database] saveAuditLogToBoth called (Supabase sync disabled)", {
    auditId: auditData.id,
    action: auditData.action,
  });
}

/**
 * Save a refund record. No-op for Supabase sync.
 */
export async function saveRefundToBoth(
  _data: Record<string, unknown>,
): Promise<void> {
  // No-op stub
}

/**
 * Save a billing history record. No-op for Supabase sync.
 */
export async function saveBillingHistoryToBoth(
  _data: Record<string, unknown>,
): Promise<void> {
  // No-op stub
}

/**
 * Save a waitlist record. No-op for Supabase sync.
 */
export async function saveWaitlistToBoth(
  _data: Record<string, unknown>,
): Promise<void> {
  // No-op stub
}

/**
 * Save user preferences. No-op for Supabase sync.
 */
export async function savePreferencesToBoth(
  _data: Record<string, unknown>,
): Promise<void> {
  // No-op stub
}
