<?php
namespace App\Services;use App\Models\{CompetitorAudit,ProjectCompetitor,User};use Illuminate\Support\Str;
final class CompetitorAuditLogger{public function record(string$action,ProjectCompetitor$c,User$actor,array$before=[]):void{$safe=fn($v)=>array_intersect_key($v,array_flip(['name','domain','normalized_domain','status','archived_at']));CompetitorAudit::create(['actor_user_id'=>$actor->id,'project_id'=>$c->project_id,'competitor_id'=>$c->id,'action'=>$action,'correlation_id'=>(string)Str::uuid(),'before'=>$safe($before)?:null,'after'=>$safe($c->fresh()->attributesToArray())]);}}
