<?php

namespace Tests\Unit\Framework;

use App\Filters\ProductModel;
use Openguru\OpenCartFramework\CriteriaBuilder\Criterion;
use Openguru\OpenCartFramework\CriteriaBuilder\RuleSerializer;
use Tests\TestCase;

class RuleSerializerTest extends TestCase
{
    public function testSerialize(): void
    {
        $rulesSerializer = new RuleSerializer();

        $productName = new ProductModel(
            ProductModel::NAME,
            [
                'product_model' => new Criterion('string', [
                    'operator' => 'contains',
                    'keyword' => 'foobar',
                ])
            ]
        );

        $expected = [
            'id' => 'RULE_PRODUCT_MODEL',
            'criteria' => [
                'product_model' =>
                    [
                        'type' => 'string',
                        'params' => [
                            'operator' => 'contains',
                            'keyword' => 'foobar',
                        ]
                    ]
            ],
            '__meta' => [
                'group' => 'other',
            ],
        ];
        $actual = $rulesSerializer->toArray($productName);

        $this->assertEquals($expected, $actual);
    }
}