<?php

namespace CouponsPlus\App\Coupon\Tree\Notifications\Buttons;

use stdClass;
use CouponsPlus\Original\Collections\Collection;

class ButtonFactory
{
    public function create(string $text, string $urlType, string $urlValue) : Button
    {
        $urls = new Collection([
            SmartURL::TYPE => SmartURL::class,
            DirectURL::TYPE => DirectURL::class,
            ShopURL::TYPE => ShopURL::class,
            PageURL::TYPE => PageURL::class,
        ]);

        $URL = $urls->get($urlType);

        $url = new $URL($urlValue, $URL::TYPE === SmartURL::TYPE? new ShopURL : null);

        return new Button($text, $url);
    }

    public function createFromButtonData(stdClass $buttonData) : Button
    {
        return $this->create($buttonData->text, $buttonData->url->type, $buttonData->url->value);
    }
}