<?php

namespace App\Traits;

trait TracksImportStats
{
    protected int $itemsProcessed = 0;
    protected int $itemsCreated = 0;
    protected int $itemsUpdated = 0;
    protected int $itemsFailed = 0;

    protected function resetStats(): void
    {
        $this->itemsProcessed = 0;
        $this->itemsCreated = 0;
        $this->itemsUpdated = 0;
        $this->itemsFailed = 0;
    }

    protected function incrementProcessed(): void
    {
        $this->itemsProcessed++;
    }

    protected function incrementCreated(): void
    {
        $this->itemsCreated++;
        $this->itemsProcessed++;
    }

    protected function incrementUpdated(): void
    {
        $this->itemsUpdated++;
        $this->itemsProcessed++;
    }

    protected function incrementFailed(): void
    {
        $this->itemsFailed++;
        $this->itemsProcessed++;
    }

    public function getImportStats(): array
    {
        return [
            'processed' => $this->itemsProcessed,
            'created' => $this->itemsCreated,
            'updated' => $this->itemsUpdated,
            'failed' => $this->itemsFailed,
        ];
    }
}
