<?php

namespace App\Services\Moderation;

use App\Models\ContentModerationActionLog;
use App\Models\ContentModerationFinding;
use App\Models\User;

class ContentModerationActionLogService
{
    /**
     * @param array<string, mixed>|null $meta
     */
    public function log(
        ?ContentModerationFinding $finding,
        string $targetType,
        ?int $targetId,
        string $actionType,
        ?User $actor = null,
        ?string $oldStatus = null,
        ?string $newStatus = null,
        ?string $oldVisibility = null,
        ?string $newVisibility = null,
        ?string $notes = null,
        ?array $meta = null,
    ): ContentModerationActionLog {
        return ContentModerationActionLog::query()->create([
            'finding_id' => $finding?->id,
            'target_type' => $targetType,
            'target_id' => $targetId,
            'action_type' => $actionType,
            'actor_type' => $actor ? 'admin' : 'system',
            'actor_id' => $actor?->id,
            'old_status' => $oldStatus,
            'new_status' => $newStatus,
            'old_visibility' => $oldVisibility,
            'new_visibility' => $newVisibility,
            'notes' => $notes,
            'meta_json' => $meta,
            'created_at' => \now(),
        ]);
    }
}