<?php

namespace Lightscale\LaralightSvg;

class SvgService
{
    protected array $collections = [];

    public function __construct()
    {
        $collections = config('svg.collections');

        foreach ($collections as $k => $collection) {
            $this->addCollectionConfig($k, $collection);
        }
    }

    protected function addCollectionFromConfig(
        string $collectionName,
        array $collectionConfig
    ): void
    {
        $c = new SvgCollection($collectionName);

        foreach ($collectionConfig['paths'] as $p) {
            $c->addPath($p);
        }

        $this->addCollection($c);
    }


    public function addCollection(SvgCollection $collection): void
    {
        $this->collections[$collection->getName()] = $collection;
    }

    public function registerCollection(string $collection): void
    {
        $this->addCollection(new SvgCollection($collection));
    }

    public function addCollectionPath(string $collection, string $path): void
    {
        $this->collections[$collection]->addPath($path);
    }

    public function getSvgUrl(string $collection, string $svg): string
    {
        return $this->collections[$collection]->getSvgUrl($collection, $svg);
    }

}