<?php

declare(strict_types=1);

namespace App\Filament\Resources\DberpTransferOrders\Pages;

use App\Business\Inventory\Enums\TransferDocumentStatus;
use App\Filament\Resources\DberpTransferOrders\DberpTransferOrderResource;
use App\Filament\Resources\Pages\CreateRecord;

class CreateDberpTransferOrder extends CreateRecord
{
    protected static string $resource = DberpTransferOrderResource::class;

    protected function mutateFormDataBeforeCreate(array $data): array
    {
        $data['status'] = TransferDocumentStatus::Draft->value;
        $data['business_time'] = $data['business_time'] ?? now();

        $data = app('App\\Business\\MasterData\\DberpDocumentAddressSnapshotService')->fillWarehouseSnapshot($data, 'from_warehouse_id', 'from_warehouse');

        return app('App\\Business\\MasterData\\DberpDocumentAddressSnapshotService')->fillWarehouseSnapshot($data, 'to_warehouse_id', 'to_warehouse');
    }
}