import Shortify, { DatabaseConfig } from "../src/index";

async function demonstrateCollectionNamePreservation() {
  console.log(
    "=== Collection/Table Name Preservation Across All Database Engines ===\n"
  );

  const customCollectionName = "MyCustomCollection";
  const customTableName = "MyCustomTable";

  console.log("1. MongoDB Collection Name Preservation:");
  console.log(`   Custom collection name: "${customCollectionName}"`);
  console.log("   - Previously: Automatically converted to lowercase");
  console.log("   - Now: Preserved exactly as specified\n");

  console.log("2. SQLite Table Name Preservation:");
  console.log(`   Custom table name: "${customTableName}"`);
  console.log(
    "   - Previously: Converted to lowercase on case-insensitive filesystems"
  );
  console.log(
    "   - Now: Preserved exactly as specified using quoted identifiers\n"
  );

  console.log("3. PostgreSQL Table Name Preservation:");
  console.log(`   Custom table name: "${customTableName}"`);
  console.log("   - Previously: Converted to lowercase when unquoted");
  console.log(
    "   - Now: Preserved exactly as specified using quoted identifiers\n"
  );

  console.log("4. MySQL Table Name Preservation:");
  console.log(`   Custom table name: "${customTableName}"`);
  console.log(
    "   - Previously: Converted to lowercase on case-insensitive filesystems"
  );
  console.log(
    "   - Now: Preserved exactly as specified using backtick quotes\n"
  );

  // Demonstrate with SQLite (in-memory for easy testing)
  console.log("5. Testing with SQLite (in-memory):");
  const sqliteConfig: DatabaseConfig = {
    type: "sqlite",
    database: ":memory:",
    tableName: customTableName,
  };

  const shortify = new Shortify("https://short.ly", sqliteConfig);
  await shortify.connect();

  // Create a URL to test that the table name is preserved
  const result = await shortify.shorten("https://example.com/test-url");
  console.log(`   Created URL with ID: ${result.urlId}`);
  console.log(`   Table name "${customTableName}" was used successfully`);
  console.log("   ✓ Table name preservation working correctly\n");

  await shortify.disconnect();

  console.log("6. Configuration Examples for All Database Types:");
  console.log("   MongoDB:");
  console.log(`     collectionName: "${customCollectionName}"`);
  console.log("   SQLite/PostgreSQL/MySQL:");
  console.log(`     tableName: "${customTableName}"`);
  console.log(
    "\n   All database engines now preserve the exact case and formatting specified!"
  );

  console.log("\n=== Collection Name Preservation Complete ===");
}

// Run the demonstration
demonstrateCollectionNamePreservation().catch(console.error);
