/**
 * Rule: naming-convention/interface-filename
 * Enforces naming conventions for interface files
 */
export default {
  meta: {
    type: 'suggestion',
    docs: {
      description: 'Enforces naming conventions for interface files',
    },
    messages: {
      mismatch: `Interface files must follow the pattern "I[A-Z]*.ts". Example: "IAlertProps.ts"`,
    },
  },
  create(context) {
    const filename = context.getFilename();
    const isInInterfacesFolder = filename.includes('/interfaces/') || filename.includes('\\interfaces\\');

    // Early return if not in interfaces folder
    if (!isInInterfacesFolder) {
      return {};
    }

    const basename = filename.split(/[\\/]/).pop();
    const regex = /^I[A-Z].*\.ts$/;

    if (!regex.test(basename)) {
      context.report({
        messageId: 'mismatch',
        loc: { line: 1 },
      });
    }

    return {};
  },
};
