<?php

declare(strict_types=1);

namespace App\Filament\Resources\DberpStocktakeOrders\Pages;

use App\Business\Inventory\Enums\InventoryDocumentStatus;
use App\Filament\Resources\DberpStocktakeOrders\DberpStocktakeOrderResource;
use App\Filament\Resources\Pages\CreateRecord;
use App\Models\DberpStocktakeOrder;

class CreateDberpStocktakeOrder extends CreateRecord
{
    protected static string $resource = DberpStocktakeOrderResource::class;

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

        (new DberpStocktakeOrder($data))->assertScopeFieldsForSave();

        return $data;
    }
}
