<?php

namespace Lightscale\LaralightSvg\Console\Commands;

use Lightscale\LaralightSvg\SvgService;
use Lightscale\LaralightSvg\SvgCollection;

use Illuminate\Console\Command;

class SvgClearState extends Command
{
    protected $signature = 'svg:clear {collection?}';

    protected $description = 'Clear svg state stored in cache';

    public function __construct(
        protected SvgService $svg,
    ) {
        parent::__construct();
    }

    public function handle()
    {
        $collection = $this->argument('collection');

        if ($collection === null) {
            foreach ($this->svg->getCollections() as $collection) {
                $collection->clearState();
            }
        }
        else {
            $this->svg->getCollection($collection)->clearState();
        }

        return Command::SUCCESS;
    }

}