/**
 * Simple test for page-query-must-use-builders rule
 */

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

// Simulate the AST traversal
const mockContext = {
  getSourceCode: () => ({ ast: {} }),
  report: (data) => {
    console.log('REPORT:', data.messageId);
  }
};

const visitor = rule.create(mockContext);

// Simulate visiting AdminDashboardPageQuery
console.log('Starting test...');

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

// 2. MethodDefinition (execute)
visitor.MethodDefinition({
  key: { type: 'Identifier', name: 'execute' },
  parent: { type: 'ClassBody' }
});

// 3. VariableDeclarator (const apiDto = ...) - NOT an ObjectExpression
visitor.VariableDeclarator({
  init: { type: 'CallExpression' } // apiDto = await adminService.getDashboardStats()
});

// 4. ReturnStatement (return Result.ok(apiDto))
// This is a CallExpression with callee = Result.ok and argument = apiDto
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']({
  key: { type: 'Identifier', name: 'execute' }
});

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

console.log('Test complete');
