<?php

namespace App\Filament\Resources\PricelistFiles\Pages;

use App\Enums\PricelistFileStatusEnum;
use App\Filament\Resources\PricelistFiles\PricelistFileResource;
use App\Services\PricelistFileProcessService;
use Filament\Actions\DeleteAction;
use Filament\Actions\ForceDeleteAction;
use Filament\Actions\RestoreAction;
use Filament\Actions\ViewAction;
use Filament\Resources\Pages\EditRecord;

class EditPricelistFile extends EditRecord
{
    protected static string $resource = PricelistFileResource::class;

    protected function getHeaderActions(): array
    {
        return [
            ViewAction::make(),
            DeleteAction::make(),
            ForceDeleteAction::make(),
            RestoreAction::make(),
        ];
    }

    protected function afterSave(): void
    {
        if ($this->record->status === PricelistFileStatusEnum::fail) {
            app(PricelistFileProcessService::class)->dispatchInitialChain($this->record);
        }
    }
}
