<?php

$models = [
    'Branch.php', 'Department.php', 'Designation.php', 'Employee.php',
    'Shift.php', 'Policy.php', 'Holiday.php', 'Machine.php',
    'LeaveType.php', 'ManualPunch.php', 'Punch.php'
];

$dir = __DIR__ . '/app/Models/';

foreach ($models as $model) {
    $path = $dir . $model;
    if (file_exists($path)) {
        $content = file_get_contents($path);
        
        // Ensure trait isn't already added
        if (strpos($content, 'use \App\Traits\TracksSuperadmin;') === false) {
            // Add the trait inside the class, right after opening brace
            $content = preg_replace(
                '/class\s+[A-Za-z0-9_]+\s*(?:extends\s+[A-Za-z0-9_\\\\]+\s*)?\{/s',
                "$0\n    use \\App\\Traits\\TracksSuperadmin;\n",
                $content,
                1
            );
            file_put_contents($path, $content);
            echo "Added trait to $model\n";
        } else {
            echo "Trait already in $model\n";
        }
    } else {
        echo "File not found: $model\n";
    }
}
