/**
 * Fixed test with proper parent structure
 */

const rule = require('./page-query-must-use-builders.js');

const mockContext = {
  getSourceCode: () => ({ ast: {} }),
  report: (data) => {
    console.log('✓ REPORT:', data.messageId);
  }
};

const visitor = rule.create(mockContext);

console.log('=== Fixed Test ===\n');

// 1. ClassDeclaration
const classNode = {
  id: { name: 'AdminDashboardPageQuery' }
};
visitor.ClassDeclaration(classNode);

// 2. MethodDefinition (with proper parent structure)
const methodNode = {
  key: { type: 'Identifier', name: 'execute' },
  parent: {
    type: 'ClassBody',
    parent: classNode  // This is what was missing!
  }
};
visitor.MethodDefinition(methodNode);

// 3. VariableDeclarator
visitor.VariableDeclarator({
  init: { type: 'CallExpression' }
});

// 4. ReturnStatement
visitor.ReturnStatement({
  argument: {
    type: 'CallExpression',
    callee: {
      type: 'MemberExpression',
      object: { type: 'Identifier', name: 'Result' },
      property: { type: 'Identifier', name: 'ok' }
    },
    arguments: [{ type: 'Identifier', name: 'apiDto' }]
  }
});

// 5. MethodDefinition:exit
visitor['MethodDefinition:exit'](methodNode);

// 6. Program:exit
visitor['Program:exit']();

console.log('\n=== Done ===');
