<?php

declare(strict_types=1);

/**
 * @author Amasty Team
 * @copyright Copyright (c) Amasty (https://www.amasty.com)
 * @package Page Speed Tools for Magento 2 (System)
 */

namespace Amasty\PageSpeedTools\Model\Image;

use Amasty\PageSpeedTools\Model\Image\ReplacePatterns\ReplaceConfigInterface;
use Magento\Framework\DataObject;

class ImagesDataByPattern extends DataObject
{
    public const REPLACE_PATTERN = 'replace_pattern';
    public const RESOLVED_IMAGES = 'resolved_images';
    public const IMAGES = 'images';
    public const IMAGE_STRING_WITH_TAG = 'image';
    public const IMG_PATHS = 'img_paths';

    /**
     * @param ReplaceConfigInterface $replacePattern
     * @return ImagesDataByPattern
     */
    public function setReplacePattern(ReplaceConfigInterface $replacePattern): ImagesDataByPattern
    {
        return $this->setData(self::REPLACE_PATTERN, $replacePattern);
    }

    /**
     * @return ReplaceConfigInterface
     */
    public function getReplacePattern(): ReplaceConfigInterface
    {
        return $this->_getData(self::REPLACE_PATTERN);
    }

    /**
     * @param array $resolvedImages => [
     * 'image' => 'image string with tag',
     * 'img_paths' => ['http://yoursite/img.jpg', ... ]
     * ]
     * @return ImagesDataByPattern
     */
    public function setResolvedImages(array $resolvedImages): ImagesDataByPattern
    {
        return $this->setData(self::RESOLVED_IMAGES, $resolvedImages);
    }

    /**
     * @return array
     */
    public function getResolvedImages(): array
    {
        return $this->_getData(self::RESOLVED_IMAGES) ?? [];
    }

    /**
     * @param array $images => [parsed images by regex]
     * @return ImagesDataByPattern
     */
    public function setImages(array $images): ImagesDataByPattern
    {
        return $this->setData(self::IMAGES, $images);
    }

    /**
     * @return array
     */
    public function getImages(): array
    {
        return $this->_getData(self::IMAGES) ?? [];
    }
}
