import { Interface } from "../schema/mode/interfaces/Interface";
import { When } from "../schema/extensions/components/ConditionalValidation";

console.log("🔥 NEW CLEAR CONDITIONAL SYNTAX TEST");
console.log("=====================================\n");

console.log("✨ Comparing syntax clarity:");
console.log("❌ Old confusing: when:role=admin:string[]:number");
console.log("✅ New clear:     when(role=admin) then(string[]) else(number)");
console.log("");

// 🔥 NEW CLEAR SYNTAX EXAMPLES
console.log("1️⃣ NEW CLEAR SYNTAX (Recommended!)");
console.log("===================================");

const NewClearSchema = Interface({
    // Basic fields
    role: "admin|user|guest",
    accountType: "free|premium|enterprise",
    age: "int(13,120)",
    
    // 🔥 NEW CLEAR SYNTAX - Much easier to read!
    permissions: "when(role=admin) then(string[]) else(string[]?)",
    maxProjects: "when(accountType=free) then(int(1,3)) else(int(1,))",
    paymentMethod: "when(accountType!=free) then(string) else(string?)",
    billingAddress: "when(paymentMethod.exists) then(string) else(string?)",
    accessLevel: "when(age>=18) then(string) else(string?)",
    
    // Basic fields
    id: "positive",
    email: "email",
    name: "string(2,50)"
});

console.log("✅ New clear syntax schema created successfully!");

// Test the new clear syntax
const newResult = NewClearSchema.safeParse({
    role: "admin",
    accountType: "premium",
    age: 25,
    permissions: ["read", "write", "delete"],
    maxProjects: 50,
    paymentMethod: "credit_card",
    billingAddress: "123 Main St",
    accessLevel: "full",
    id: 1,
    email: "admin@example.com",
    name: "Admin User"
});

console.log("✅ New clear syntax validation:", newResult.success);
if (newResult.success && newResult.data) {
    console.log("   Role:", newResult.data.role);
    console.log("   Permissions:", newResult.data.permissions);
    console.log("   Access Level:", newResult.data.accessLevel);
} else {
    console.log("   Errors:", newResult.errors);
}

// 🔄 BACKWARD COMPATIBILITY TEST
console.log("\n2️⃣ BACKWARD COMPATIBILITY TEST");
console.log("===============================");

const LegacySchema = Interface({
    role: "admin|user|guest",
    accountType: "free|premium|enterprise",
    
    // 🔄 Legacy syntax still works for backward compatibility
    permissions: "when:role=admin:string[]:string[]?",
    maxProjects: "when:accountType=free:int(1,3):int(1,)",
    
    id: "positive",
    email: "email"
});

const legacyResult = LegacySchema.safeParse({
    role: "admin",
    accountType: "premium",
    permissions: ["read", "write"],
    maxProjects: 100,
    id: 2,
    email: "user@example.com"
});

console.log("✅ Legacy syntax still works:", legacyResult.success);
if (legacyResult.success && legacyResult.data) {
    console.log("   Backward compatibility maintained!");
} else {
    console.log("   Errors:", legacyResult.errors);
}

// 🎯 SYNTAX COMPARISON
console.log("\n3️⃣ SYNTAX CLARITY COMPARISON");
console.log("=============================");

console.log("🔥 NEW CLEAR SYNTAX (Recommended):");
console.log('   permissions: "when(role=admin) then(string[]) else(string[]?)"');
console.log('   maxProjects: "when(accountType=free) then(int(1,3)) else(int(1,))"');
console.log('   paymentMethod: "when(accountType!=free) then(string) else(string?)"');
console.log('   accessLevel: "when(age>=18) then(string) else(string?)"');

console.log("\n🔄 LEGACY SYNTAX (Still supported):");
console.log('   permissions: "when:role=admin:string[]:string[]?"');
console.log('   maxProjects: "when:accountType=free:int(1,3):int(1,)"');
console.log('   paymentMethod: "when:accountType!=free:string:string?"');

console.log("\n📦 IMPORT-BASED SYNTAX (Most powerful):");
console.log("   permissions: When.field('role').is('admin').then('string[]').else('string[]?')");

// 🎉 SUMMARY
console.log("\n🎉 SYNTAX IMPROVEMENT SUMMARY");
console.log("=============================");
console.log("✅ NEW: Crystal clear syntax with parentheses");
console.log("✅ LEGACY: Backward compatibility maintained");
console.log("✅ IMPORT: Full power for complex scenarios");
console.log("✅ CHOICE: Pick the syntax that fits your needs");

console.log("\n🚀 Revolutionary improvement: Conditional validation is now crystal clear!");
console.log("   when(condition) then(schema) else(schema) - Easy to read and understand!");
console.log("   No more confusion about where conditions start and end!");
