module.exports = {
  meta: {
    type: 'problem',
    docs: {
      description: 'Enforce controller location in apps/api',
      category: 'Architecture',
      recommended: true,
    },
    fixable: null,
    schema: [],
    messages: {
      invalidLocation: 'Controllers must be located in "src/domain/<feature>/" or "src/features/". Found: {{location}}',
    },
  },

  create(context) {
    return {
      ClassDeclaration(node) {
        const isController = node.decorators && node.decorators.some(d => 
          d.expression.type === 'CallExpression' && 
          d.expression.callee.name === 'Controller'
        );

        if (isController) {
          const filename = context.getFilename();
          const isValidLocation = /apps\/api\/src\/(domain\/[^/]+\/|features\/)/.test(filename);

          if (!isValidLocation) {
            context.report({
              node,
              messageId: 'invalidLocation',
              data: {
                location: filename,
              },
            });
          }
        }
      },
    };
  },
};
