<?php

declare(strict_types=1);

/*
 * This file is part of the VITICORE2 package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Tests\Product;

use CpCreation\VitiCore\Product\Model\Product;
use CpCreation\VitiCore\Product\Model\ProductType;
use CpCreation\VitiCore\Product\Model\ProductVariant;
use CpCreation\VitiCore\Product\ProductVariantSkuResolver;
use PHPUnit\Framework\TestCase;

final class ProductVariantSkuResolverTest extends TestCase
{
    public function testBuildsSkuFromProductAndStableTypeCode(): void
    {
        $product = new Product();
        $product->setSku('BRUT-RESERVE');
        $type = new ProductType();
        $type->setCode('75 cl');
        $variant = new ProductVariant();
        $variant->setProduct($product);
        $variant->setType($type);

        self::assertSame('75-CL', $type->getCode());
        self::assertSame('BRUT-RESERVE-75-CL', new ProductVariantSkuResolver()->resolve($variant));
    }

    public function testExplicitVariantSkuTakesPriority(): void
    {
        $product = new Product();
        $product->setSku('BRUT-RESERVE');
        $type = new ProductType();
        $type->setCode('MAGNUM');
        $variant = new ProductVariant();
        $variant->setProduct($product);
        $variant->setType($type);
        $variant->setSku('BRUT-RESERVE-GIFT');

        self::assertSame('BRUT-RESERVE-GIFT', new ProductVariantSkuResolver()->resolve($variant));
    }

    public function testReturnsNullWithoutProductOrVariantSku(): void
    {
        self::assertNull(new ProductVariantSkuResolver()->resolve(new ProductVariant()));
    }
}
