<?php

namespace App\Filament\Resources\RetentionOverrideResource\Pages;

use App\Enums\RetentionOverrideScope;
use App\Filament\Resources\Pages\AuditedCreateRecord;
use App\Filament\Resources\RetentionOverrideResource;
use Filament\Facades\Filament;

class CreateRetentionOverride extends AuditedCreateRecord
{
    protected static string $resource = RetentionOverrideResource::class;

    protected function mutateFormDataBeforeCreate(array $data): array
    {
        $data['created_by_id'] = Filament::auth()->id();
        $data['released_at'] = null;
        $data['released_by_id'] = null;

        if (($data['scope'] ?? null) !== RetentionOverrideScope::EVENT->value) {
            $data['event_id'] = null;
        }

        return $data;
    }
}
