<?php

namespace Modules\Routing\Filament\Resources\EvRoutes\Pages;

use Filament\Notifications\Notification;
use Filament\Resources\Pages\CreateRecord;
use Modules\Routing\Filament\Resources\EvRoutes\EvRouteResource;

class CreateEvRoute extends CreateRecord
{
    protected static string $resource = EvRouteResource::class;

    protected function beforeCreate(): void
    {
        if (
            ($this->data['is_active'] ?? false)
            && ! EvRouteResource::hasCompletePricingData($this->data['pricing'] ?? [])
        ) {
            Notification::make()
                ->warning()
                ->title('Route cannot be activated yet')
                ->body('Set a price above 0 for every non-blocked vehicle option first, then activate the route.')
                ->send();

            $this->halt();
        }
    }
}
