import { isTypeNameException } from '../utils/index.js';

/**
 * Rule: naming-convention/type-alias
 * Enforces naming conventions for type aliases
 */
export default {
  meta: {
    type: 'suggestion',
    docs: {
      description: 'Enforces naming conventions for type aliases - no "Type" suffix and singular names',
    },
    messages: {
      mismatch: `Type name "{{ typeName }}" must not end with "Type".`,
      plural: `Type name "{{ typeName }}" must be singular; plural names are not allowed.`,
    },
  },
  create(context) {
    return {
      TSTypeAliasDeclaration(node) {
        const typeName = node.id.name;

        // Skip exceptions
        if (isTypeNameException(typeName)) {
          return;
        }

        // Check if type name ends with "Type"
        if (typeName.endsWith('Type')) {
          context.report({
            node: node.id,
            messageId: 'mismatch',
            data: { typeName },
          });
        }

        // Check if type name appears plural (simple heuristic: ends with 's')
        if (typeName.endsWith('s')) {
          context.report({
            node: node.id,
            messageId: 'plural',
            data: { typeName },
          });
        }
      },
    };
  },
};
