<?php

namespace App\Filament\Resources\CustomerResource\Pages;

use App\Filament\Resources\CustomerResource;
use App\Models\Customers\Customer;
use App\Services\AuditLog;
use Filament\Resources\Pages\CreateRecord;

class CreateCustomer extends CreateRecord
{
    protected static string $resource = CustomerResource::class;

    protected function afterCreate(): void
    {
        /** @var Customer $customer */
        $customer = $this->record;

        AuditLog::record('customer.created', $customer, [
            'name' => $customer->business_name,
            'email' => $customer->email,
        ]);
    }

    protected function getRedirectUrl(): string
    {
        return CustomerResource::getUrl('index');
    }
}
