import { Interface } from "../schema/mode/interfaces/Interface";

console.log("🔧 SIMPLE PARENTHESES SYNTAX TEST");
console.log("=================================\n");

// Test simple parentheses syntax without nested parentheses
const SimpleParenthesesSchema = Interface({
  role: "admin|user|guest",
  
  // Simple parentheses syntax without nested parentheses
  permissions: "when(role=admin) then(string) else(string?)",
  
  id: "positive",
  name: "string"
});

console.log("✅ Simple parentheses syntax schema created successfully!");

// Test TypeScript type inference
const testData = {
  role: "admin" as const,
  permissions: "read", // Should be inferred as string
  id: 1,
  name: "Admin User"
};

const result = SimpleParenthesesSchema.safeParse(testData);
console.log("✅ Simple parentheses test:", result.success);

// Test with type error - this should show TypeScript error if type inference works
const invalidData = {
  role: "admin" as const,
  permissions: 123, // ❌ Should show TypeScript error: number instead of string
  id: 1,
  name: "Admin User"
};

console.log("🎯 Testing TypeScript error detection for simple parentheses syntax...");
console.log("If you see a TypeScript error above, type inference is working!");

// Now test with array syntax that has nested parentheses
const ArrayParenthesesSchema = Interface({
  role: "admin|user|guest",
  
  // This has nested parentheses: string[]
  permissions: "when(role=admin) then(string[]) else(string[]?)",
  
  id: "positive",
  name: "string"
});

console.log("✅ Array parentheses syntax schema created successfully!");

// Test with array data
const arrayTestData = {
  role: "admin" as const,
  permissions: ["read", "write"], // Should be inferred as string[]
  id: 1,
  name: "Admin User"
};

const arrayResult = ArrayParenthesesSchema.safeParse(arrayTestData);
console.log("✅ Array parentheses test:", arrayResult.success);

// Test with array type error
const invalidArrayData = {
  role: "admin" as const,
  permissions: ["read", "write", 2], // ❌ Should show TypeScript error: number in string[]
  id: 1,
  name: "Admin User"
};

console.log("🎯 Testing TypeScript error detection for array parentheses syntax...");
console.log("If you see a TypeScript error above, array type inference is working!");

console.log("\n🔧 PARENTHESES SYNTAX ANALYSIS");
console.log("==============================");
console.log("✅ Simple parentheses: when(condition) then(string) else(string?)");
console.log("🔧 Array parentheses: when(condition) then(string[]) else(string[]?)");
console.log("📝 The issue might be with nested parentheses in TypeScript template literals");
