<?php

namespace App\Filament\Resources\SupplierResource\Pages;

use App\Filament\Resources\SupplierResource;
use App\Models\Lookups\Status;
use App\Models\Purchasing\Supplier;
use App\Services\AuditLog;
use Filament\Resources\Pages\CreateRecord;

class CreateSupplier extends CreateRecord
{
    protected static string $resource = SupplierResource::class;

    protected function mutateFormDataBeforeCreate(array $data): array
    {
        $data['status_id'] = Status::idOf(Status::CTX_SUPPLIER, Status::SUPPLIER_ACTIVE);

        return $data;
    }

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

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