#!/usr/bin/env node

/**
 * Script to fix TypeScript imports in domain/services
 * Replace relative paths with path aliases
 */

const fs = require('fs');
const path = require('path');

function fixImportsInFile(filePath) {
  const content = fs.readFileSync(filePath, 'utf8');
  let modified = content;

  // Replace relative imports to ../ports/ with @domain/ports/
  modified = modified.replace(/from ['"]\.\.\/ports\//g, "from '@domain/ports/");
  modified = modified.replace(/import\s+(['"])\.\.\/ports\//g, 'import $1@domain/ports/');

  if (modified !== content) {
    fs.writeFileSync(filePath, modified, 'utf8');
    return true;
  }
  return false;
}

const servicesDir = path.join(__dirname, 'src/domain/services');
console.log('🔧 Fixing domain/services imports...\n');

const files = fs.readdirSync(servicesDir);
let count = 0;

for (const file of files) {
  if (file.endsWith('.ts')) {
    const filePath = path.join(servicesDir, file);
    if (fixImportsInFile(filePath)) {
      console.log(`✅ Fixed: ${filePath}`);
      count++;
    }
  }
}

console.log(`\n✅ Fixed ${count} files in domain/services`);
